标签:计蒜客
#include <cstdio> #include <iostream> #include <cstring> using namespace std; char str[10000008]; int main(){ char c ; int status = 0; strcpy(str,"0k"); int flag = 0; int s = 0; int len = 2; while((c = getchar())!= '\n'){ if((status == 0 ||status == 1) && c == '0'){ status = 1; } else if(status == 1 && c == 'k'){ status = 2; s = 1; } else if(status == 2 && ((c <= '9' &&c >='0') || (c <= 'E' && c >= 'A'))){ if(s==1 && c == '0'){ s = 2; } else{ s = 0; } str[len++] = c; if(s == 2){ str[len] = 0; printf("%s\n",str); flag = 0; status = 0; strcpy(str,"0k"); len = 2; continue; } flag = 1; }else if(status == 2 && !((c <= '9' &&c >='0') || (c <= 'E' && c >= 'A'))){ if(flag == 1) { str[len] = 0; printf("%s\n",str); } strcpy(str,"0k"); len = 2; status = 0; flag = 0; } else if(status == 1 &&c != 'k' ){ status = 0; } } if(flag == 1){ str[len] = 0; printf("%s\n",str); } return 0; }
注意0k012是输出0k0
注意不能用string类
注意状态转移之间的关系!
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:计蒜客
原文地址:http://blog.csdn.net/qq_24667639/article/details/46942841