#問題1
#include <stdio.h>
#define N 100
int main(void){
char s[N], *p1 = s, *p2 = p1;
int l;
printf("文字列A : ");
scanf("%s", s);
while (*p1++);
printf("文字列B : ");
scanf("%s", s);
while (*p2++);
l = p1 - p2;
if (l == 0)
printf("二つの文字列は同じ長さです.\n");
if (l < 0)
printf("文字列B の方が%d 文字長いです.\n", -l);
if (l > 0)
printf("文字列A の方が%d 文字長いです.\n", l);
return 0;
}
#問題2
#include <stdio.h>
#define N 100
int main(void){
char s[N], *p1 = s, *p2 = p1;
printf("文字列 : ");
fgets(s, N, stdin);
while (*p2)
p2++;
p2 -= 2;
while ((p1 < p2) && (*p1 == *p2)) {
p1++;
p2--;
}
if (p1 >= p2)
printf("回文です。\n");
else
printf("回文ではありません。\n");
return 0;
}