### Solved Problem 17

parent b8bafd19
Showing with 79 additions and 0 deletions
17/README 0 → 100644
 Question: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? NOTE: Do not count spaces or hyphens. 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. Answer: 21124
17/main.cpp 0 → 100644
 #include #include using namespace std; int main() { map numbers; int key = 0; numbers = 3; numbers = 3; numbers = 5; numbers = 4; numbers = 4; numbers = 3; numbers = 5; numbers = 5; numbers = 4; numbers = 3; numbers = 6; numbers = 6; numbers = 8; numbers = 8; numbers = 7; numbers = 7; numbers = 9; numbers = 8; numbers = 8; numbers = 6; numbers = 6; numbers = 5; numbers = 5; numbers = 5; numbers = 7; numbers = 6; numbers = 6; numbers = 11; for(int i = 21; i < 1000; i++) { key = i; if((key < 100 && key %10 == 0)) continue; numbers[i] = 0; if(key >= 100) { numbers[i] = numbers[key / 100] + 7; key = (key % 100); if(i%100 != 0) numbers[i] += 3; else continue; } if(key <= 20 || key % 10 == 0 || key > 100) numbers[i] += numbers[key]; else numbers[i] += numbers[key%10] + numbers[(key/10) * 10]; } key = 0; for(int i = 1; i <= 1000; i++) { key += numbers[i]; } cout << key << endl; return 0; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!