阿拉伯数字转化为中文(缩写)数值

Posted qiuhaifeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了阿拉伯数字转化为中文(缩写)数值相关的知识,希望对你有一定的参考价值。

阿拉伯数字转化为中文(缩写)数值:

#include<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
using namespace std;

string tostring(int a)
    stringstream ss;
    ss<<a;
    string res;
    ss>>res;
    return res;

int main()
    int a;
    cin>>a;
    string res;
    vector<char>arr'S','B','Q','W';
    int pos=0;
    while(a!=0)
        if(pos==5)
            pos=1;
        
        if(pos==0)
            if(a%10)
                res.push_back(char(a%10+'0'));
            
        pos=pos+1;
        
        else
            if(a%10)
                res.push_back(arr[pos-1]);
                res.push_back(char(a%10+'0'));
            
            pos=pos+1;
        
        a=a/10;
    
    reverse(res.begin(),res.end());
    cout<<res;
    return 0;

以上是关于阿拉伯数字转化为中文(缩写)数值的主要内容,如果未能解决你的问题,请参考以下文章