码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-09-09 22:30:07      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:stream   str   ace   name   数值   names   else   code   algorithm   

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

#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;

}

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

标签:stream   str   ace   name   数值   names   else   code   algorithm   

原文地址:https://www.cnblogs.com/qiuhaifeng/p/11494382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!