如果用C语言写一个程序,判断字符串是否为两组相同的小字符串组成,如果是输出yes。例如abcabc,输出yes ,abcabcabc输入no
1条回答 默认 最新
benbenli 2021-05-08 23:06关注#include<stdio.h> #include<string.h> int main() { int N,i,j; char S[101]; printf("input N: "); scanf("%d",&N); printf("input S: "); scanf("%s",S); if(strlen(S)!=N) { printf("error\n"); printf("input S: "); scanf("%s",S); } if (N % 2 == 1) { printf("no"); return 0; } for(i = 0; i<N/2; ++i) { if (S[i] != S[i + N/2]) { printf("no"); return 0; } } printf("yes"); return 0; } // Output input N: 6 input S: abcabc yes input N: 6 input S: abcabc yes附注:求赞助积分和C币。加入CSDN将近20年了。最近几年忙小孩没登录。刚才搜索到一本电子书想下载,需要20积分/C币。已经收到8元了,还差12元。赞助多少都可以。多谢。
本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用