AC代码:
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int ele[20] = {0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3,6, 6, 8, 8, 7, 7, 9, 8, 8};
int ten[11] = {0, 3, 6, 6, 5, 5, 5, 7, 6, 6, 7};
int dot[4] = {0, 8, 7, 7};
string eles[20] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
string tens[11] = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "nithty", "hundrad"};
string dots[4] = {"", "thousand", "million", "billion"};
int analyse(int x)
{
int a = x / 100;
int b = x % 100;
int out = 0;
if(a)
{
if(a / 10)
{
out += ele[a / 10] + dot[1]; // thousand
}
if(a % 10)
{
out += ele[a % 10] + ten[10]; // hundrad
}
if(b)
{
out += 3;
}
}
if(b >= 20)
{
out += ele[b % 10] + ten[b / 10];
}
else
{
out += ele[b];
}
return out;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
int sum = 0;
int t;
scanf("%d",&t);
for(int i = 1; i <= t; i++) sum += analyse(i);
cout << sum << endl;
}
return 0;
}