3976 - 输出逆序数
数字逆序的例子为 12345的逆序数为54321。即把一个十进制的数逆序输出。
本题要求编写程序当给出一个5位数的输入时候输出它的逆序数。
Input
只有一行,一个5位数
Output
输入的5位数的逆序数
Examples
Input
12345
Output
54321
Solution C
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int a; scanf("%d",&a); printf("%d",a%10*10000+(a%100-a%10)*100+a%1000-a%100+(a%10000-a%1000)/100+(a-a%10000)/10000); return 0; }
Solution C++
#include <iostream> #include <cstdio> using namespace std; int main() { int n; cin>>n; do { cout<<n%10; n=n/10; }while(n!=0); return 0; }