xiaoqianqian @ 2023-07-08 12:34:35
using namespace std;
int main(){
string s;
cin >> s;
int n = s.size();
for (int i = n; i >= 0; i--){
cout << s[i];
}
return 0;
}
by FengYuXinMing @ 2023-07-08 13:01:08
@xiaoqianqian 有没有种可能,n应该是n-1?因为下标要-一位,所以要n-1
by FengYuXinMing @ 2023-07-08 13:01:29
@xiaoqianqian 然后,你不导入头文件吗?
by __Octhyccc__ @ 2023-07-08 13:27:39
@xiaoqianqian
字符串长度统计从1开始,但是字符串像数组一样,下标从0开始计,所以应该是这样的:
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=s.length()-1;i>=0;i--){
printf("%c",s[i]);
}
return 0;
}
by xiaoqianqian @ 2023-07-09 18:53:50
@EXPQWE 谢了,头文件是因为复制的时候好像漏掉了(?