HDU 5867 - Water problem ( 模拟 )
题意
one:3个字母,two:3个字母,three:5个字母…..求到n<=1000,1—1000所有单词字母数量的和
For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of “and” when writing out numbers is in compliance with British usage.
思路
大模拟,把特殊单词处理好就ok
AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int getonenum( int n ){ //19以内
switch(n){
case 1 : return 3; case 2 : return 3; case 3 : return 5;
case 4 : return 4; case 5 : return 4; case 6 : return 3;
case 7 : return 5; case 8 : return 5; case 9 : return 4;
case 10: return 3; case 11: return 6; case 12: return 6;
case 13: return 8; case 14: return 8; case 15: return 7;
case 16: return 7; case 17: return 9; case 18: return 8;
case 19: return 8;
}
}
int zhengshi( int n ){ //整十的 20 -- 90
switch(n){
case 2 : return 6; case 3 : return 6; case 4 : return 5;
case 5 : return 5; case 6 : return 5; case 7 : return 7;
case 8 : return 6; case 9 : return 6;
}
}
int gettwonum( int n ){
int a = n / 10, b = n % 10;
if( n <= 19 ) return getonenum(n);
else if( b == 0 ) return zhengshi(a);
else return zhengshi(a)+getonenum(b);
}
int getnum(int n){
//hunderd == 7
if( n <= 19 ) return getonenum(n);
else if( n < 100 ) return gettwonum(n);
else if( n == 100 ) return 10;
else if( n < 1000 ){
int x = n;
int c = x % 10; x /= 10;
int b = x % 10; x /= 10;
int a = x;
//cout << a << ' ' << b << ' ' << c << endl;
if( c == 0 && b == 0 ){
return getonenum(a)+7;
}
else if( b*10+c <= 19 ){
return getonenum(a)+7+3+getonenum(b*10+c);
}
else if( c == 0 ){
return getonenum(a)+7+3+zhengshi(b);
}
else{
return getonenum(a)+7+3+zhengshi(b)+getonenum(c);
}
}
else if( n == 1000 ) return 11; //one thousand
}
int solve( int n ){
int sum = 0;
for( int i = 1; i <= n; i++ ){
sum += getnum(i);
}
return sum;
}
int main()
{
int T, n;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
printf("%d\n",solve(n));
}
return 0;
}