因为卡在第一篇题解的while循环的可以来看看
查看原帖
因为卡在第一篇题解的while循环的可以来看看
1269755
qyzzyqlqj楼主2024/3/2 22:41

这第一篇题解的输入好像有问题,卡在while里出不来,我修改了一下,本蒟蒻第一篇评论,希望能帮到大家,以下是代码:


#include<bits/stdc++.h>
using namespace std;
string str[1001];
int main(){
	string s;
	getline(cin,s);
	int a=0;
	for(int i=0;i<s.size();i++){
		if(s[i]==' '){
			a++;
			continue;
		}
		str[a]+=s[i];
	}
	//以上是修改的部分 
	for(int i = a; i >= 0; i--) {
		for(int j = 0; j < (int)str[i].size(); j++) {
			if(str[i][j] >= 'a' && str[i][j] <= 'z') str[i][j] -= 'a' - 'A';
			else if(str[i][j] >= 'A' && str[i][j] <= 'Z') str[i][j] -= 'A' - 'a'; 
		}
		if(str[i][0] >= '0' && str[i][0] <= '9')
			for(int j = (int)str[i].size() - 1; j >= 0; j--) cout << str[i][j];
		else cout << str[i];
		if(i != 0) cout << " ";
	}
	return 0;
}
2024/3/2 22:41
加载中...