Repository navigation
Expand file tree
/
Copy pathP017.cpp
More file actions
51 lines (51 loc) · 1.69 KB
/
Copy pathP017.cpp
File metadata and controls
51 lines (51 loc) · 1.69 KB
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
#include <iostream>
using namespace std;
const char Uni[20]={-1+sizeof("zero"),-1+sizeof("one"),-1+sizeof("two"),-1+sizeof("three"),-1+sizeof("four"),-1+sizeof("five"),
-1+sizeof("six"),-1+sizeof("seven"),-1+sizeof("eight"),-1+sizeof("nine"),
-1+sizeof("ten"),-1+sizeof("eleven"),-1+sizeof("twelve"),-1+sizeof("thirteen"),-1+sizeof("fourteen"),
-1+sizeof("fifteen"),-1+sizeof("sixteen"),-1+sizeof("seventeen"),
-1+sizeof("eighteen"),-1+sizeof("nineteen")};
const char Dez[10]={-1+sizeof(""),-1+sizeof(""),-1+sizeof("twenty"),-1+sizeof("thirty"),-1+sizeof("forty"),-1+sizeof("fifty"),
-1+sizeof("sixty"),-1+sizeof("seventy"),-1+sizeof("eighty"),-1+sizeof("ninety")};
unsigned int P017(unsigned int Nm){
int N;
int S=0;
do{
N=Nm;
if(N){
int U=N%10;
int D=(N/=10)%10;
int C=(N/=10)%10;
int M=(N/=10)%10;
if(M){
S+=Uni[M]+-1+sizeof("thousand");
if(C+D+U){
S+=-1+sizeof("and");
}
}
if(C){
S+=Uni[C]+-1+sizeof("hundred");
if(D+U){
S+=-1+sizeof("and");
}
}
if(D>1){
S+=Dez[D];
if(U){
S+=Uni[U];
}
}else{
if(D*10+U){
S+=Uni[D*10+U];
}
}
}else{
S+=Uni[0];
}
}while(--Nm);
return S;
}
int main() {
cout<<P017(1000)<<endl;
return 0;
}