- 数字反转
- 2016-11-08 22:39:46 @
评测结果
编译成功
测试数据 #0: Accepted, time = 15 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #6: WrongAnswer, time = 0 ms, mem = 560 KiB, score = 0
测试数据 #7: Accepted, time = 15 ms, mem = 560 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10
WrongAnswer, time = 30 ms, mem = 564 KiB, score = 90
代码
#include<iostream>
#include<cstring>
using namespace std;
char s[16];
int num=0;//正数
long long ans;
int main()
{
cin>>s;
if(s[0]=='-')
num=1;//负数
int len=strlen(s);
for(int i=len-1-num;i>=0+num;i--)
{
ans*=10;
ans+=s[i]-'0';
}
if(num)
cout<<'-';
cout<<ans;
return 0;
}
1 条评论
-
唐复之 LV 8 @ 2016-11-08 22:48:32
评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10 测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10 Accepted, time = 0 ms, mem = 560 KiB, score = 100 代码 #include<iostream> #include<cstring> using namespace std; char s[16]; int num=0;//正数 long long ans; int main() { cin>>s; if(s[0]=='-') num=1;//负数 int len=strlen(s); for(int i=len-1;i>=0+num;i--) { ans*=10; ans+=s[i]-'0'; } if(num) cout<<'-'; cout<<ans; return 0; }
原先小题大做了……
- 1