就是这题。我在dev c++里,能跑出来,而且用不同的测试字符串跑的都是正确的,但提交给洛谷OJ就是全错。麻烦各位大神指点指点。谢谢。
先放我自己写的代码,dev C++等跑得通,而且我放不同的测试字符串上去也能正确。
#include<bits/stdc++.h>
using namespace std;
const int MAX_WORD=1000;
const int MAX_LENGTH=6;
string a;
int main(){
getline(cin,a);
int slen=a.length();
int words=0,ws_count=0,start=0;
char c[MAX_WORD][MAX_LENGTH]={};
for(int i=0;i<=slen;i++){
if(a[i]==' ' || a[i]=='\0'){
for(int j=0;j<ws_count;j++){
int asc_temp=(int)a[start+j];
if(asc_temp>=65 && asc_temp<=90){
c[words][j]=(char)(asc_temp+32);
}else if(asc_temp>=97 && asc_temp<=122){
c[words][j]=(char)(asc_temp-32);
}else if(asc_temp>=48 && asc_temp<=57){
c[words][j]=a[start+ws_count-1-j];
}else{
c[words][j]=a[start+j];
}
}
words++;
ws_count=0;
start=i-ws_count+1;
}else{
ws_count++;
}
}
for(int k=words-1;k>=0;k--){
int temp_lenth=sizeof(c[k]);
for(int l=0;l<temp_lenth;l++){
cout<<c[k][l];
}
if(k!=0)cout<<" ";
}
return 0;
}
下面是网上参考的代码(dev c++根本没跑得动),但洛谷OJ却全部AC正确
#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 << " ";
}
return 0;
}