Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <map>
  6.  
  7. #include <cctype>
  8. #include <stdlib.h>
  9. #include <string>
  10. using namespace std;
  11.  
  12. const int maxn = 1000000 + 10;
  13.  
  14. char s[maxn]; //(use to store each line)
  15. map<string, int> m; //(map English words to numbers)
  16.  
  17. int main()
  18. {
  19.  
  20. //playing table method, map all English words showed above to corresponding numbers
  21. m["negative"] = -1; m["zero"] = 0; m["one"] = 1;
  22. m["two"] = 2; m["three"] = 3; m["four"] = 4;
  23. m["five"] = 5; m["six"] = 6; m["seven"] = 7; m["eight"] = 8; m["nine"] = 9; m["ten"] = 10;
  24. m["eleven"] = 11; m["twelve"] = 12; m["thirteen"] = 13; m["fourteen"] = 14; m["fifteen"] = 15; m["sixteen"] = 16;
  25. m["seventeen"] = 17; m["eighteen"] = 18; m["nineteen"] = 19; m["twenty"] = 20; m["thirty"] = 30; m["forty"] = 40;
  26. m["fifty"] = 50; m["sixty"] = 60; m["seventy"] = 70; m["eighty"] = 80; m["ninety"] = 90;
  27. m["hundred"] = 100; m["thousand"] = 1000; m["million"] = 1000000;
  28. while (gets(s))
  29. {
  30. int len = strlen(s);
  31. if (len == 0) //(it is end if the length of the line is 0)
  32. break;
  33. __________(1)_________;
  34.  
  35. //ensure there will be a character(not alphabet) after each word
  36. s[len] = '\0';
  37. long long int ans = 0, tmp = 0;
  38. int is_negative = 0;
  39. //million,thousand
  40. //calculate how many millions, thousands and ones it has, add them up
  41. for (int i = 0; i< len; i++)
  42. {
  43. if (isalpha(s[i])) //(if it is true, there will be a beginning of a word)
  44. {
  45. string t = "";
  46. while (isalpha(s[i])) //(a word will be ended, if a blank is read)
  47. ______(2)________;
  48. //(there are 4 special words need to judge and deal with)
  49. if (m[t] == -1)
  50. {
  51. is_negative = 1;
  52. }
  53. else if (m[t] == 100)
  54. {
  55. _______(3)________;
  56. }
  57. else if (m[t] == 1000)
  58. {
  59. _______(4)________;
  60. _______(5)________;
  61. tmp = 0;
  62. }
  63. else if (m[t] == 1000000)
  64. {
  65. ________(6)_________;
  66. ________(7)________;
  67. tmp = 0;
  68. }
  69. else
  70. {
  71. tmp += m[t];
  72. }
  73. }
  74. }
  75. _________(8)_________;
  76. if (is_negative) //judge if minus is needed)
  77. cout << '-';
  78. cout << ans << endl;
  79. }
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement