C++实现整数值转中文大写-创新互联

#include
#include
using namespace std;
string zhCN[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
//正常记账范围内数值
string zhUNIT[] = { "拾","佰","仟","万","拾","佰","仟","亿" ,"拾","佰","仟","万", "拾","佰","仟"};
int main()
{
 //12,345 ,678, 902
 while (1) {
  char cc[32];
  scanf("%s", cc);
  string str_value(cc);
  cout << "input value is " << str_value.c_str() << endl;
  stacknValue;
  for (int i = 0; i < str_value.length(); i++)
  {
   const char cc = str_value.at(i);
   nValue.push((cc - '0'));
  }
  stackcn;
  int ii = 0;
  int zcount = 0;
  while (!nValue.empty())
  {
   int value = nValue.top();
   cn.push(zhCN[value]);
   cn.push(zhUNIT[ii]);
   nValue.pop();
   ii++;
  }
  if (!cn.empty())
  {
   cn.pop();
  }
  //删除零
  stackcn2;
  while (!cn.empty())
  {
   while (cn.top() != zhCN[0])
   {
    cn2.push(cn.top());
    cn.pop();
    if (cn.empty())
    {
     break;
    }
   }
   if (cn.empty())
   {
    break;
   }
   //找到零结束
   while (cn.top() == zhCN[0])
   {
    
    cn.pop();
    if (cn.empty())
    {
     break;
    }
    if (cn.top() == zhUNIT[3])//保留万
    {
     cn2.push(zhUNIT[3]);
    }
    if (cn.top() == zhUNIT[7])//保留亿
    {
     cn2.push(zhUNIT[7]);
    }
    cn.pop();
   }//找到零结束
   if (!cn.empty())
   {
    cn2.push(zhCN[0]);
   }
   
  }
  stackcn3;
  string newstr = "";  
  while (!cn2.empty())
  {
   cn3.push(cn2.top());
   cn2.pop();
  }
  while (!cn3.empty())
  {   
   newstr += cn3.top();
   cn3.pop();
  }  
  cout << "newstr is " << newstr.c_str() << endl;
 }
 return 0;
}

成都创新互联是专业的赫山网站建设公司,赫山接单;提供成都网站建设、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行赫山网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:C++实现整数值转中文大写-创新互联
网站路径:http://myzitong.com/article/cdphhd.html