Advertisement
juanjo12x

UVA_417_World_Index

Aug 13th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #include <sstream>
  14. #include <stdlib.h>
  15. #include <cmath>
  16. #define FOR(i,A) for(typeof (A).begin() i = (A).begin() ; i != (A).end() ; i++)
  17. #define mp make_pair
  18. #define debug( x ) cout << #x << " = " << x << endl
  19. #define clr(v,x) memset( v, x , sizeof v )
  20. #define all(x) (x).begin() , (x).end()
  21. #define rall(x) (x).rbegin() , (x).rend()
  22. #define TAM 110
  23.  
  24. using namespace std;
  25.  
  26. typedef pair<int,int> ii ;
  27. typedef long long ll ;
  28. typedef long double ld ;
  29. typedef pair<int,ii> pii ;
  30.  
  31.  
  32. map<string, int> dict;
  33.  
  34. void preproc() {
  35.     int count = 1;
  36.     char s[6];
  37.     for (s[0] = 'a'; s[0] <= 'z'; s[0]++) {
  38.         s[1] = '\0';
  39.         dict[string(s)] = count++;
  40.     }
  41.     for (s[0] = 'a'; s[0] <= 'z' - 1; s[0]++)
  42.         for (s[1] = s[0] + 1; s[1] <= 'z'; s[1]++) {
  43.             s[2] = '\0';
  44.             dict[string(s)] = count++;
  45.         }
  46.  
  47.     for (s[0] = 'a'; s[0] <= 'z' - 2; s[0]++)
  48.         for (s[1] = s[0] + 1; s[1] <= 'z' - 1; s[1]++)
  49.             for (s[2] = s[1] + 1; s[2] <= 'z'; s[2]++) {
  50.                 s[3] = '\0';
  51.                 dict[string(s)] = count++;
  52.             }
  53.  
  54.     for (s[0] = 'a'; s[0] <= 'z' - 3; s[0]++)
  55.         for (s[1] = s[0] + 1; s[1] <= 'z' - 2; s[1]++)
  56.             for (s[2] = s[1] + 1; s[2] <= 'z' - 1; s[2]++)
  57.                 for (s[3] = s[2] + 1; s[3] <= 'z'; s[3]++) {
  58.                     s[4] = '\0';
  59.                     dict[string(s)] = count++;
  60.                 }
  61.  
  62.     for (s[0] = 'a'; s[0] <= 'z' - 4; s[0]++)
  63.         for (s[1] = s[0] + 1; s[1] <= 'z' - 3; s[1]++)
  64.             for (s[2] = s[1] + 1; s[2] <= 'z' - 2; s[2]++)
  65.                 for (s[3] = s[2] + 1; s[3] <= 'z' - 1; s[3]++)
  66.                     for (s[4] = s[3] + 1; s[4] <= 'z'; s[4]++) {
  67.                         s[5] = '\0';
  68.                         dict[string(s)] = count++;
  69.                     }
  70. }
  71.  
  72. int main() {
  73.     char s[6];
  74.  
  75.     preproc();
  76.     while (scanf("%s", s) != EOF) {
  77.         if (dict.count(string(s)) == 0)
  78.             printf("0\n");
  79.         else
  80.             printf("%d\n", dict[string(s)]);
  81.     }
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement