ASOUL_Official @ 2020-03-26 10:43:53
//洛谷 P5705 【深基2.例7】数字反转
//Author 深入浅出
#include<bits/stdc++.h>
using namespace std;
int main(){
string num;
int lengths;
cin>>num;
for(lengths=num.length();lengths>=0;lengths--){
cout<<num[lengths];
}
return 0;
}
(输出结果)
(似乎输出了一个奇怪的字符)
编号32141342
by ASOUL_Official @ 2020-03-26 10:44:45
我为啥觉得输出的奇怪字符是\n
by Micro_Seven @ 2020-03-26 10:46:37
@lancdn 乱码
by Micro_Seven @ 2020-03-26 10:47:34
for(lengths=num.length();lengths>=0;lengths--)
应改为
for(lengths=num.length()-1;lengths>=0;lengths--)
by ASOUL_Official @ 2020-03-26 13:57:46
@Micro_Seven 收到,谢谢大佬(话说那个乱码是不是真的是换行符之类的字符)
by Micro_Seven @ 2020-03-26 14:41:59
@lancdn 内存越界
by Micro_Seven @ 2020-03-26 14:42:29
@lancdn 以后用str.at(i)
,不要用str[i]
by AFO1 @ 2020-03-27 13:41:04
string建议你用(string类型).size()