1 条题解
-
0
C :
#include<stdio.h> int main() { int n,i,m,k,s=0; scanf("%d",&n); m=n; k=n; while(m!=0) { m=m/10; s++; } printf("%d\n",s); if(s==1) printf("%d\n",n); if(s==2) printf("%d %d\n",n/10,n%10); if(s==3) printf("%d %d %d\n",n/100,n/10%10,n%10); if(s==4) printf("%d %d %d %d\n",n/1000,n/100%10,n/10%10,n%10); if(s==5) printf("%d %d %d %d %d\n",n/10000,n/1000%10,n/100%10,n/10%10,n%10); for(i=0;i<s;i++) { printf("%d",k%10); k=k/10; } printf("\n"); return 0; }
C++ :
#include <iostream> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; int main(int argc, char** argv) { int n; cin>>n; int sum=0; int s=1; int nn=n; int nnn=n; while(n>0){ n=n/10; sum++; s=s*10; } s=s/10; cout<<sum<<endl; while(s>0){ cout<<nn/s<<" "; nn=nn%s; s=s/10; } cout<<endl; while(nnn>0){ cout<<nnn%10; nnn=nnn/10; } return 0; }
Java :
import java.util.Scanner; public class Main{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int w = 0; int a,b,c,d,e; if(n < 10 ) { w = 1; System.out.println(w); System.out.println(n); System.out.println(n); }else if(n < 100) { w = 2; a = n / 10; b = n % 10; System.out.println(w); System.out.println(a +" " + b); System.out.println(b * 10 + a); }else if(n < 1000) { w = 3; a = n / 100; b = n / 10 % 10; c = n % 10; System.out.println(w); System.out.println(a +" " + b + " " + c); System.out.println(c * 100 + b * 10 + a); }else if(n < 10000) { w = 4; a = n / 1000; b = n / 100 % 10; c = n / 10 % 10; d = n % 10; System.out.println(w); System.out.println(a +" " + b +" " + c + " " + d); System.out.println(d * 1000 + c * 100 + b * 10 + a); }else if(n < 100000) { w = 5; a = n / 10000; b = n / 1000 % 10; c = n / 100 % 10; d = n / 10 % 10; e = n % 10; System.out.println(w); System.out.println(a +" " + b +" " + c + " " + d + " " + e); System.out.println(e * 10000 + d * 1000 + c * 100 + b * 10 + a); } } }
Python :
# 接收输入一个不大于5位的数字 n = int(input()) # 初始化计数位数c c = 0 a = [] # 初始化求和 b = 0 m = n while n > 0: # s就是个位上的数字 s = n % 10 # 每次得出个位数,就加入到a列表中 a.insert(0, s) # n地板除10,得出除了个位数以外的整数,进行下一次循环 n //= 10 # 计数位数自加1 c += 1 print(c) # 遍历列表,求出每一个元素,并打印输出 for v in a: print(v, end=' ') print() #逆序输出 while m > 0: #最先得出的余数乘以10,再加上第二次的余数,再循环得出逆序数 b = b * 10 + m % 10 m //= 10 print(b)
- 1
信息
- ID
- 2782
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者