问题分析:1.数据比较大,并且输入数据时没有停顿,所有使用字符串来存储数据
string str="";
cin>>str;
2.使用字符串数组来存储每个数字的拼音
string S[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
3.从后往前得到数据的每位数,使用栈来逆序存储一下
栈的操作
入栈
stack.push();
出栈
stack.pop();
4.注意输出格式
完整的代码:
#include<iostream>
#include<stack>
using namespace std;
typedef long long ll;
string str="";
string S[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
stack<int> mystack;
int main(){cin>>str;ll num=str.size();ll ans=0;for(ll i=0;i<num;i++){ans+=str[i]-'0';}//从各位向前 一位一位的输出 while(ans){mystack.push(ans%10);ans=ans/10; }cout<<S[mystack.top()];mystack.pop();while(!mystack.empty()){cout<<" ";cout<<S[mystack.top()];mystack.pop();}}