给出一个数,不多于五位,1.求出他是几位数2.分别打印出每位数3.倒序输出

#include <iostream>

using namespace std;

int main()
{
    int a,temp;
    int ten_thousand,thousand,hundred,ten,indiv;
    cin>>a;
    if(a>9999)
    temp=5;
    else if(a>999)
    temp=4;
    else if(a>99)
    temp=3;
    else if(a>9)
    temp=2;
    else temp=1;
    cout<<temp<<endl;
    ten_thousand=a/10000;
    thousand=(a-ten_thousand*10000)/1000;
    hundred=(a-ten_thousand*10000-thousand*1000)/100;
    ten=(a-ten_thousand*10000-thousand*1000-hundred*100)/10;
    indiv=a-ten_thousand*10000-thousand*1000-hundred*100-ten*10;
    switch(temp)
    {
        case 5:cout<<ten_thousand<<" "<<thousand<<" "<<hundred<<" "<<ten<<" "<<indiv<<endl;
               cout<<indiv<<" "<<ten<<" "<<hundred<<" "<<thousand<<" "<<ten_thousand<<endl;
               break;
        case 4:cout<<thousand<<" "<<hundred<<" "<<ten<<" "<<indiv<<endl;
               cout<<indiv<<" "<<ten<<" "<<hundred<<" "<<thousand<<endl;
               break;
        case 3:cout<<hundred<<" "<<ten<<" "<<indiv<<endl;
               cout<<indiv<<" "<<ten<<" "<<hundred<<endl;
               break;
        case 2:cout<<ten<<" "<<indiv<<endl;
               cout<<indiv<<" "<<ten<<endl;
               break;
        case 1:cout<<indiv<<endl;
               cout<<indiv<<endl;
               break;

    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值