C语言程序设计题,要求设计一个满足下列条件的字符串,每个1后面都有0直接跟着

来源:百度知道 编辑:UC知道 时间:2024/05/25 07:42:00
满足条件的打印YES
不满足的打印NO

#include "stdlib.h"
#include "string.h"
main()
{
char str1[80],*p1,*p2;
char str2[]="10";
int flag=1;
gets(str);
p1=str1;p2=str2;
while(*p1!='\0')
{
if(*p1==*p2)
{
while(*p1==*p2&&*p2!=0)
{
p1++;
p2++;
}
}
else
p1++;
if(*p=='\0')
p2=str2;
else
{
flag=0;break;
}
}
if(flag==1)
printf("YES");
else
printf("NO");
}

#include <stdio.h>
int main()
{
char string[100];
printf("请输入您要测试的字符串:\n");
scanf("%s",string);
for(int i=0; i<100; i++)
{
if(string[i] == '1')
{
if(string[i+1]!='0')
{
printf("NO\n");
return 1;
}
}
}
printf("YES\n");
return 0;
}