打印每位数

题目描述

输入一个不多于四位的正整数,求出它是几位数,并分别打印出各位上的数字。
 

输入

输入一个不多于四位的正整数x。

输出

第一行输出x的位数num,接下来num行从高位到低位输出x的每一位上的数字。
 

样例输入

123

样例输出

3
1
2
3
 

数据范围限制

1<=x<=9999

 

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
 
int main()
{
 
       int n,ans;
	cin>>n;
	vector<int> v;
	
	while(n>0)
	{
	    ans = n%10;
	    n/=10;
	 
	  v.push_back(ans);
	}
    
    cout<<v.size()<<endl;
    
    for(vector<int>::iterator it=v.end(); it!=v.begin();)     //逆序输出
    {
    	cout<<*(--it)<<endl;
    }
	return 0;
}

  

posted @ 2018-11-07 20:20  道微真理  阅读(164)  评论(0)    收藏  举报