|
//这是MS-VC++ 6.0写的,跟Dev-C++差好多,
//用了很久都没找出方法在VC++ 6开头使用string的自定函数.
//上面的只要using namespace std;搬到int main()里就剩3个问题了.
//也就是上面Dev-C++写的第二行string aX(int)这行搞定就可以.
//但是我都用不出来,因为VC++没用过,又刚学DevC++只好改写.
//问题就在string 在第二行不能被接受….
//
//以下是改写成MS-VC++ 6.0版的,但”零”没有特别处理,
//如何改善和精简程序,请自行研究了
//我的功力在VC++ 6只能写到此程度…不好意思.
#include <iostream>
#include <string>
int main()
{
using namespace std;
int qX=0;
int x0,x1,x2,x3,x4;
cout <<"请输入数字(5位数内): ";
cin >> qX;
x4 = qX%1000000%100000/10000;
x3 = qX%1000000%100000%10000/1000; //1万的余数就是千,有几千呢?? ,再除以1000就是了.
x2 = qX%1000000%100000%10000%1000/100; //万的余数是千,千的余数剩百,几百再除以100就是了.
x1 = qX%1000000%100000%10000%1000%100/10;//同上推演下来...
x0 = qX%1000000%100000%10000%1000%100%10;//同上推演下来...
if(qX>99999){cout <<"数字太大"; return 0;}
string aa0,aa1,aa2,aa3,aa4;
//万位数
if(x4 == 0){aa4="零";}
if(x4 == 1){aa4="一";}
if(x4 == 2){aa4="二";}
if(x4 == 3){aa4="三";}
if(x4 == 4){aa4="四";}
if(x4 == 5){aa4="五";}
if(x4 == 6){aa4="六";}
if(x4 == 7){aa4="七";}
if(x4 == 8){aa4="八";}
if(x4 == 9){aa4="九";}
cout << aa4 <<"万";
//千位数
if(x3 == 0){aa3="零";}
if(x3 == 1){aa3="一";}
if(x3 == 2){aa3="二";}
if(x3 == 3){aa3="三";}
if(x3 == 4){aa3="四";}
if(x3 == 5){aa3="五";}
if(x3 == 6){aa3="六";}
if(x3 == 7){aa3="七";}
if(x3 == 8){aa3="八";}
if(x3 == 9){aa3="九";}
cout << aa3 <<"千";
//百位数
if(x2 == 0){aa2="零";}
if(x2 == 1){aa2="一";}
if(x2 == 2){aa2="二";}
if(x2 == 3){aa2="三";}
if(x2 == 4){aa2="四";}
if(x2 == 5){aa2="五";}
if(x2 == 6){aa2="六";}
if(x2 == 7){aa2="七";}
if(x2 == 8){aa2="八";}
if(x2 == 9){aa2="九";}
cout << aa2 <<"百";
//十位数
if(x1 == 0){aa1="零";}
if(x1 == 1){aa1="一";}
if(x1 == 2){aa1="二";}
if(x1 == 3){aa1="三";}
if(x1 == 4){aa1="四";}
if(x1 == 5){aa1="五";}
if(x1 == 6){aa1="六";}
if(x1 == 7){aa1="七";}
if(x1 == 8){aa1="八";}
if(x1 == 9){aa1="九";}
cout << aa1 <<"十";
//个位数
if(x0 == 0){aa0="零";}
if(x0 == 1){aa0="一";}
if(x0 == 2){aa0="二";}
if(x0 == 3){aa0="三";}
if(x0 == 4){aa0="四";}
if(x0 == 5){aa0="五";}
if(x0 == 6){aa0="六";}
if(x0 == 7){aa0="七";}
if(x0 == 8){aa0="八";}
if(x0 == 9){aa0="九";}
cout << aa0 <<endl;
return 0;
} |
|