1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include<sstream>
#include<iostream>
#include<strstream>
using namespace std;
string numbers[10]={"","one","two","three","four","five","six","seven","eight","nine"};
string eleventonineteen[10]={"","eleven","tweleve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
string tennum[10]={"","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
class number
{
public:
int strlen;
int value;
void subtract();
private:
void print(int hundred ,int ten,int value);
};
void number::subtract()
{
int hundreds,tens;
for ( hundreds=0;value>=100;++hundreds,value-=100);
for ( tens=0;value>=10;++tens,value-=10);
print(hundreds,tens,value);
}
void number::print(int hundred ,int ten,int value)
{
string str;
if (hundred>0)
str+=numbers[hundred]+"hundred";
if (hundred>0&&(ten>0||value>0))
str+="and";
if(ten==1&&value>0)
str+=eleventonineteen[value];
else if (ten>0)
{
str+=tennum[ten];
if (value>0)
str+=numbers[value];
}
else if (value>0)
str+=numbers[value];
cout<<str<<" "<<str.length()<<endl;
strlen=str.length();
}
int main()
{number num;
int input,sum=0;
for ( input=0;input<1000;)
{
num.value=input;
num.subtract();
input+=1;
sum+=num.strlen;
}
cout<<sum;
getchar();
return 0;
}
|