- 数字反转
- 2016-11-08 21:39:30 @
如题。
~~~
编译成功
测试数据 #0: Accepted, time = 15 ms, mem = 576 KiB, score = 10
测试数据 #1: WrongAnswer, time = 0 ms, mem = 580 KiB, score = 0
测试数据 #2: Accepted, time = 0 ms, mem = 576 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 580 KiB, score = 10
测试数据 #4: Accepted, time = 15 ms, mem = 576 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 576 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 576 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 572 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 576 KiB, score = 10
测试数据 #9: WrongAnswer, time = 0 ms, mem = 576 KiB, score = 0
WrongAnswer, time = 60 ms, mem = 580 KiB, score = 80
~~~
#include<iostream>
using namespace std;
int h,t;string s;
int main(){
cin>>s;
t=s.length();
if(s[0]=='-'){
cout<<'-';h++;
}
for(int i=t-1;i>h;i++){
if(s[i]=='0') t--;
else break;
}
for(int i=t-1;i>=h;i--) cout<<s[i];
}
3 条评论
-
142857 LV 8 @ 2017-01-12 17:27:29
#include<stdio.h>
int main()
{
int n,ans=0;
scanf("%d",&n);
while(n)
{
ans*=10;
ans+=n%10;
n/=10;
}
printf("%d",ans);
return 0;
} -
2016-11-08 21:45:24@
……谢谢……居然过了8个点……
已对。 -
2016-11-08 21:43:29@
将
for(int i=t-1;i>h;i++){
改为
for(int i=t-1;i>h;i--){
- 1