View Code of Problem 114

#include<bits/stdc++.h>
using namespace std;
int main() {
	char c[100],c2[100];
	int count,flag=0;
	while(gets(c)) {
		//先利用空格拆分单词 然后将每个单词进行逆序输出
		count=0;//用来记录每个单词字母个数
		for(int i=0; i<strlen(c); i++) {
			//如果是字母 直接存进来 
			if((c[i]>='A'&&c[i]<='Z') || (c[i]>='a'&&c[i]<='z')) c2[count++]=c[i];
			else {
				if(c[i]==' ') {
					if(count!=0) {
						while(count>0) cout<<c2[--count];
					}
					cout<<" ";
				}else {
					if(count!=0) {
						while(count>0) cout<<c2[--count];
					}
					cout<<c[i];
				}
			}
		}
		while(count>0) cout<<c2[--count];
		cout<<endl;
	}
}

Double click to view unformatted code.


Back to problem 114