mthoutai

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#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类

注意状态转移之间的关系!


posted on 2017-06-12 14:33  mthoutai  阅读(204)  评论(0编辑  收藏  举报