1 条题解
-
0
C :
#include<stdio.h> int main() { int a,b[20],l=0,s=0,i; scanf("%d",&a); for (i = 0;;++i) { l++; b[i]=a%10; a/=10; if(a==0) break; /* code */ } for ( i = 0; i < l; ++i) { s=b[i]+s*10; /* code */ } printf("%d",s ); return 0; }
C++ :
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char a[12]; int i,count; while(scanf("%s",a)!=EOF) { if(atoi(a)==0) { printf("0\n"); continue; } count=1; if(a[0]=='-') { printf("-"); for(i=strlen(a)-1;i>=1;i--) { if(a[i]=='0'&&count==1) { continue; } if(a[i]!='0'||count==0) { count=0; printf("%c",a[i]); } } } else { for(i=strlen(a)-1;i>=0;i--) { if(a[i]=='0'&&count==1) { continue; } if(a[i]!='0'||count==0) { count=0; printf("%c",a[i]); } } } puts(""); } return 0; }
Pascal :
var s,s1,c:string; x,i,l:longint; begin readln(s); if(s='0')then begin writeln(0);exit;end; if(s='-0')then begin writeln(0);exit;end; if s[1]='-'then begin c:='-'; delete(s,1,1); end else c:=''; l:=length(s); for i:=l downto 1 do begin s1:=s1+s[i]; end; val(s1,x); str(x,s1); s1:=c+s1; writeln(s1); end.
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String a = in.next(); if(Integer.parseInt(a)>0) { StringBuilder sb = new StringBuilder(a); sb.reverse(); System.out.println(Integer.parseInt(sb.toString())); } else { char[] b = a.toCharArray(); StringBuilder sb = new StringBuilder(); for(int i=1;i<b.length;i++) sb.append(b[i]); sb.reverse(); System.out.println(Integer.parseInt(sb.toString())*-1); } } }
Python :
# coding=utf-8 def main(): def _reverse(x: int) -> int: sign = 1 if x<0: sign = -1 x = -x res = [] while x>0: res.append(x%10) x //= 10 x_ = 0 for bit in res: if x_>2**31/10: return 0 x_ = 10*x_ + bit return sign*x_ while True: temp = input() if temp == '': break x = int(temp) print(_reverse(x)) if __name__ == '__main__': main()
- 1
信息
- ID
- 284
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者