有什么区别吗?
查看原帖
有什么区别吗?
1378709
Yue_Hao楼主2024/10/7 15:34

bushi,题解的代码和我的代码的结构都差不多,为什么我的不行啊?


my code:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s[1010000];
int main(){
	ll o = -1;
	while(cin.get() != '\n') cin >> s[++o];
	for(ll i = o; i >= 0; i--){
		for(ll j = s[i].size() - 1; j >= 0; j--){
			if(s[i][j] >= 'a' && s[i][j] <= 'z') s[i][j] = s[i][j] - 'a' + 'A';
			else if(s[i][j] >= 'A' && s[i][j] <= 'Z') s[i][j] = s[i][j] - 'A' + 'a';
		}
		if(s[i][0] >= '0' && s[i][0] <= '9') reverse(s[i].begin(), s[i].end());
		cout << s[i] << ' ';
	}
	return 0;
}

题解code:

#include<bits/stdc++.h>
using namespace std;

int n;
string s[1007];

int main() {
	while(cin >> s[++n]); --n;
	for(int i = n; i >= 1; i--) {
		for(int j = 0; j < (int)s[i].size(); j++) {
			if(s[i][j] >= 'a' && s[i][j] <= 'z') s[i][j] -= 'a' - 'A';
			else if(s[i][j] >= 'A' && s[i][j] <= 'Z') s[i][j] -= 'A' - 'a'; 
		}
		if(s[i][0] >= '0' && s[i][0] <= '9')
			for(int j = (int)s[i].size() - 1; j >= 0; j--) cout << s[i][j];
		else cout << s[i];
		if(i != 1) cout << " ";
	}
}

到底哪里有问题啊?

2024/10/7 15:34
加载中...