ngcgy @ 2024-04-21 21:47:47
N = int(input())
if N == 0:
print(N)
else:
m = abs(N)
lst=[]
while m != 0:
lst.append(m%10)
m = m//10
count = len(lst)
result = 0
for k in range(len(lst)):
result = result + lst[k]*pow(10,count-1)
count = count-1
if N <0:
print(-result)
else:
print(result)
by kamikuQAQ @ 2024-04-21 21:49:00
满分不是一百分
by _buzhidao_ @ 2024-04-21 21:51:53
@ngcgy 有不设分值的Hack,应该是Subtask#1里的
by ngcgy @ 2024-04-21 22:04:29
@buzhidao 能帮我看下代码么,还有什么没考虑到么。 我用数字和字符串两种处理方法,都是一样的。 下面是用字符串处理的。
s=input()
if s=="0":
print(s)
else:
ls=[i for i in s]
ls.reverse()
result=""
if ls[-1]=="-":
result="-"
ls.pop()
while 1:
if ls[0]=="0":
ls.remove("0")
else:
break
for i in ls:
result = result + i
print(result)
by _buzhidao_ @ 2024-04-22 06:43:02
@ngcgy 抱歉,本蒟蒻不是py党。
提供C++代码:
#include<iostream>
using namespace std;
long long a,b,c;
int main(){
cin>>a;
b=a;
while(b){
c*=10;
c+=b%10;
b/=10;
}
cout<<c;
return 0;
}
只看 main()
内部部分即可。
cin>>
表示读入,cout<<
表示输出。
by starish @ 2024-05-05 18:16:20
@ngcgy ```python N = int(input()) if N == 0: print(N) else: m = abs(N) lst=[] while m != 0: lst.append(m%10) m = m//10 count = len(lst) result = 0 for k in range(len(lst)): result = result + lst[k]*pow(10,count-1) count = count-1 if N <0: print(-result) else: print(result)
缩进问题?
by starish @ 2024-05-05 18:17:35
@ngcgy subtask数据应该是0
by cao_20115 @ 2024-05-10 22:05:52
@ngcgy
特判输入为零