用C语言写了。
#include <stdio.h>
#include <string.h>
int main()
{
int n, l;
char s[101];
char *p, *m, *q;
printf("Please enter the length N: \n");
scanf("%d", &n);
if (n <= 0)
{
printf("Length must be positive.\n");
return -1;
}
else if (n %2 == 1)
{
printf("Length must be even number.\n");
return -1;
}
printf("Please enter the string S (max 100 characters): ");
scanf("%s", s);
l = strlen(s);
if (l != n)
{
printf("String length %d is not equal to %d\n", l, n);
return -1;
}
p = s;
m = s + n / 2;
q = m;
while (p < m)
{
if (*p++ != *q++)
{
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
}
// Output
Please enter the length N:
6
Please enter the string S (max 100 characters): abcabc
Yes
Please enter the length N:
6
Please enter the string S (max 100 characters): abcabd
No
附注:求赞助积分和C币。加入CSDN将近20年了。最近几年忙小孩没登录。刚才搜索到一本电子书想下载,需要20积分/C币。已经收到8元了,还差12元。赞助多少都可以。多谢。
什么编程语言呀?