1825 - 课后习题5.7
Time Limit : 1 秒
Memory Limit : 128 MB
给出一个不多于5位的整数,要求 1、求出它是几位数 2、分别输出每一位数字 3、按逆序输出各位数字,例如原数为321,应输出123
Input
一个不大于5位的数字
Output
三行 第一行 位数 第二行 用空格分开的每个数字,注意最后一个数字后没有空格 第三行 按逆序输出这个数
Examples
Input Format
12345
Output Format
5 1 2 3 4 5 54321
Solution C
#include<stdio.h> main() { int x,y=0,z,t,count=0; scanf("%d",&x); while(x!=0) { count++; t=x%10; x/=10; y=y*10+t; } printf("%d\n",count); z=y; while(y>=10) { printf("%d ",y%10); y/=10; } printf("%d\n%d\n",y%10,z); }
Solution C++
#include<bits/stdc++.h> using namespace std; string x; int main() { cin>>x; cout<<x.size()<<"\n"; for(int i=0;i<x.size();i++) cout<<x[i]<<" "; cout<<"\n"; for(int i=x.size()-1;i>=0;i--) cout<<x[i]; return 0; }