Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- #include <map>
- #include <cctype>
- #include <stdlib.h>
- #include <string>
- using namespace std;
- const int maxn = 1000000 + 10;
- char s[maxn]; //(use to store each line)
- map<string, int> m; //(map English words to numbers)
- int main()
- {
- //playing table method, map all English words showed above to corresponding numbers
- m["negative"] = -1; m["zero"] = 0; m["one"] = 1;
- m["two"] = 2; m["three"] = 3; m["four"] = 4;
- m["five"] = 5; m["six"] = 6; m["seven"] = 7; m["eight"] = 8; m["nine"] = 9; m["ten"] = 10;
- m["eleven"] = 11; m["twelve"] = 12; m["thirteen"] = 13; m["fourteen"] = 14; m["fifteen"] = 15; m["sixteen"] = 16;
- m["seventeen"] = 17; m["eighteen"] = 18; m["nineteen"] = 19; m["twenty"] = 20; m["thirty"] = 30; m["forty"] = 40;
- m["fifty"] = 50; m["sixty"] = 60; m["seventy"] = 70; m["eighty"] = 80; m["ninety"] = 90;
- m["hundred"] = 100; m["thousand"] = 1000; m["million"] = 1000000;
- while (gets(s))
- {
- int len = strlen(s);
- if (len == 0) //(it is end if the length of the line is 0)
- break;
- __________(1)_________;
- //ensure there will be a character(not alphabet) after each word
- s[len] = '\0';
- long long int ans = 0, tmp = 0;
- int is_negative = 0;
- //million,thousand
- //calculate how many millions, thousands and ones it has, add them up
- for (int i = 0; i< len; i++)
- {
- if (isalpha(s[i])) //(if it is true, there will be a beginning of a word)
- {
- string t = "";
- while (isalpha(s[i])) //(a word will be ended, if a blank is read)
- ______(2)________;
- //(there are 4 special words need to judge and deal with)
- if (m[t] == -1)
- {
- is_negative = 1;
- }
- else if (m[t] == 100)
- {
- _______(3)________;
- }
- else if (m[t] == 1000)
- {
- _______(4)________;
- _______(5)________;
- tmp = 0;
- }
- else if (m[t] == 1000000)
- {
- ________(6)_________;
- ________(7)________;
- tmp = 0;
- }
- else
- {
- tmp += m[t];
- }
- }
- }
- _________(8)_________;
- if (is_negative) //judge if minus is needed)
- cout << '-';
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement