标签:
12345
5
1 2 3 4 5
54321
哈姆雷特:数字还是字符?这是一个问题!
题解:
#include<stdio.h>
#include<math.h>
int
main()
{
int
num,indiv,ten,hundred,thousand,ten_thousand,place;
scanf
(
"%d"
,&num);
ten_thousand=num/10000;
thousand=(
int
)(num-ten_thousand*10000)/1000;
hundred=(
int
)(num-ten_thousand*10000-thousand*1000)/100;
ten=(
int
)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv=(
int
)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
if
(num>9999)
place=5;
else
if
(num>999)
place=4;
else
if
(num>99)
place=3;
else
if
(num>9)
place=2;
else
place=1;
printf
(
"%d\n"
,place);
switch
(place)
{
case
5:
printf
(
"%d %d %d %d %d\n"
,ten_thousand,thousand,hundred,ten,indiv);
printf
(
"%d%d%d%d%d"
,indiv,ten,hundred,thousand,ten_thousand);
break
;
case
4:
printf
(
"%d %d %d %d\n"
,thousand,hundred,ten,indiv);
printf
(
"%d%d%d%d"
,indiv,ten,hundred,thousand);
break
;
case
3:
printf
(
"%d %d %d\n"
,hundred,ten,indiv);
printf
(
"%d%d%d"
,indiv,ten,hundred);
break
;
case
2:
printf
(
"%d %d\n"
,ten,indiv);
printf
(
"%d%d"
,indiv,ten);
break
;
case
1:
printf
(
"%d\n"
,indiv);
printf
(
"%d"
,indiv);
break
;
}
return
0;
}
#include<stdio.h>
int
main() {
int
x,y[5],i,j;
scanf
(
"%d"
,&x);
for
(i=0;x!=0;i++) {
y[i]=x%10;
x=x/10;
}
printf
(
"%d\n"
,i);
for
(j=i-1;j>0;j--)
printf
(
"%d "
,y[j]);
printf
(
"%d"
,y[0]);
putchar
(
‘\n‘
);
for
(j=0;j<i;j++)
printf
(
"%d"
,y[j]);
putchar
(
‘\n‘
);
return
0;
}
标签:
原文地址:http://www.cnblogs.com/SSYYGAM/p/4211082.html