您的位置:首页 > 其它

给出一个不多于5位的整数,要求 1、求出它是几位数 2、分别输出每一位数字 3、按逆序输出各位数字,例如原数为321,应输出123

2013-04-25 20:05 736 查看
哎,搞了半天才搞出来,现在才知道自己技术真么差,要好好努力了
#include<iostream>
using namespace std;
//#include<stdio.h>
//#include<math.h>
int  main()
{ 
	long int x; 
	int g,s,b,q,w; 
	int n;
	cin>>x;
	if(x>9999)     
		n=5; 
	else if(x>999)  
		n=4;      
	else if(x>99)
		n=3;
	else if(x>9)  
		n=2;    
	else   
		n=1;
	cout<<n<<endl;  
	w=x/10000; 
	q=x%10000/1000;  
	b=x%10000%1000/100; 
	s=x%10000%1000%100/10;   
	g=x%10000%1000%100%10; 
	if(w!=0) 
	{
		cout<<w<<" "<<q<<" "<<b<<" "<<s<<" "<<g<<endl;
		cout<<g<<s<<b<<q<<w<<endl;
	} 
	else if(q!=0)   
	{
		cout<<q<<" "<<b<<" "<<s<<" "<<g<<endl;
		cout<<g<<s<<b<<q<<endl;
	}
	else if(b!=0)   
    {
		cout<<b<<" "<<s<<" "<<g<<endl;
		cout<<g<<s<<b<<endl;
	}
	else if(s!=0) 
	{
		cout<<s<<" "<<g<<" "<<endl;
		cout<<g<<s<<endl;
	}
	else 
	{
		cout<<g<<endl;
		cout<<g<<endl;
	}
	return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐