7-62 切分表达式——写个tokenizer吧

#include<stdio.h>
int main(){
	char str[41];
	scanf("%s",str);
	int i;
	printf("%c",str[0]);
	for(i=1;str[i]!='\0';i++){
						if((str[0]=='+'||str[0]=='-')&&i==1){
							if(str[1]>='0'&&str[1]<='9')
					printf("%c",str[1]);
				}
		else{
		
			if(str[i]>='0'&&str[i]<='9'){

				
			if((str[i-1]>='0'&&str[i-1]<='9')||str[i-1]=='.'||str[i-1]=='-'){
				printf("%c",str[i]);
			}
			else{
				printf("\n%c",str[i]);
			}
		}
		else if(str[i]=='.'){
			printf("%c",str[i]);
		}
		else
		printf("\n%c",str[i]);
		}
}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/michaelliu6/article/details/78591200