题目
测试用例
题目解析
1, 将一个数字的每一位拆开放在一个数字中,然后进行输出
2,第二个输出的时候,每一位都有空格,最后一位没有空格需要进行特殊处理
代码模板
把数字的每一位取出来放在数组中
while(t!=0){
arr[i] = t % 10;
t = t / 10;
i++;
}
注意:第一位存放的是个位数字,以此类推
此题代码:
#include <cstdio>
#include <iostream>
using namespace std;
int t,i = 0;
int count = 1;
int arr[10];
int main(){
scanf("%d",&t);//123
while(t!=0){
arr[i] = t % 10;
t = t / 10;
i++;
}
printf("%d\n",i);
int count = i;
for(int j = i - 1;j >= 0;j--){//0 1 2
printf("%d",arr[j]);
printf(" ");
count--;
if(count==1){
printf("%d\n",arr[0]);
break;
}
}
for(int k = 0;k < i;k++){
printf("%d",arr[k]);
}
return 0;
}
当然,使用除以及取模以及众多的if语句也可以写出来!