Advertisement
palmerstone

C

Oct 16th, 2012
3,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <cctype>
  5. #include <cstdlib>
  6. #include <climits>
  7. #include <ctime>
  8. #include <istream>
  9. #include <ostream>
  10. #include <iostream>
  11. #include <iomanip>
  12. #include <algorithm>
  13. #include <vector>
  14. #include <string>
  15. #include <numeric>
  16. #include <fstream>
  17. #include <sstream>
  18. #include <map>
  19. #include <set>
  20. #include <list>
  21. #include <stack>
  22. #include <queue>
  23. #include <deque>
  24. #include <limits>
  25. #include <bitset>
  26. #include <iterator>
  27. #include <utility>
  28. #include <functional>
  29. #include <tr1/unordered_map>
  30.  
  31. #define vinf (1 << 28)
  32. #define inf ((~0U) >> (1))
  33. #define pi (2.0 * acos(0.0))
  34. #define lowbit(x) ((x) & (-(x)))
  35. #define sine(x) (sin(radians(x)))
  36. #define cosine(x) (cos(radians(x)))
  37. #define tangent(x) (tan(radians(x)))
  38. #define arcsine(x) (degrees((asin(x))))
  39. #define arccosine(x) (degrees((acos(x))))
  40. #define arctangent(x) (degrees((atan(x))))
  41. #define clr(ar) (memset(ar, 0, sizeof(ar)))
  42. #define radians(x) (((1.0 * x * pi) / 180.0))
  43. #define degrees(x) (((x * 180.0) / (1.0 * pi)))
  44. #define read() (freopen("lol.txt", "r+", stdin))
  45. #define write() (freopen("lol.txt", "w+", stdout))
  46. #define dbg(x) (std::cout << #x << " = " << x << endl)
  47. #define twopow(x) ((((x & (x - 1)) == 0) && (x != 0)) ? (true) : (false))
  48. #define mod(n, m) ((n >= 0) ? (n % m) : ((abs(n) % m) == 0) ? 0 : (m - (abs(n) % m)))
  49.  
  50. using namespace std;
  51.  
  52. int t;
  53. vector <string> v;
  54. vector <string> v2;
  55. std::tr1::unordered_map <string, string> mp;
  56. std::tr1::unordered_map <string, string> mp2;
  57. char str[5000010], key[100010], value[100010];
  58.  
  59. int main(){
  60.     //read();
  61.  
  62.     scanf("%d", &t), getchar();
  63.     for (int line = 1; line <= t; line++){
  64.         mp.clear(), mp2.clear(), v.clear(), v2.clear();
  65.         gets(str);
  66.         char* pch = strtok(str, "{,}");
  67.         while (pch != 0){
  68.             int j = 0, k = 0;
  69.             for (j = 0; pch[j] != ':'; j++) key[k++] = pch[j];
  70.             key[k] = 0, k = 0;
  71.             for (++j; pch[j] != 0; j++) value[k++] = pch[j];
  72.             value[k] = 0;
  73.             mp[key] = value;
  74.             v.push_back(key);
  75.             pch = strtok(0, "{,}");
  76.         }
  77.  
  78.         gets(str);
  79.         pch = strtok(str, "{,}");
  80.         while (pch != 0){
  81.             int j = 0, k = 0;
  82.             for (j = 0; pch[j] != ':'; j++) key[k++] = pch[j];
  83.             key[k] = 0, k = 0;
  84.             for (++j; pch[j] != 0; j++) value[k++] = pch[j];
  85.             value[k] = 0;
  86.             mp2[key] = value;
  87.             v2.push_back(key);
  88.             pch = strtok(0, "{,}");
  89.         }
  90.  
  91.         int counter = 0;
  92.         bool printed = false;
  93.         int len = v.size(), len2 = v2.size();
  94.         sort(v.begin(), v.end()), sort(v2.begin(), v2.end());
  95.  
  96.         counter = 0;
  97.         for (int i = 0; i < len2; i++){
  98.             string lol = mp[v2[i]];
  99.             if (lol.length() == 0){
  100.                 printed = true;
  101.                 if (counter != 0) putchar(',');
  102.                 if (counter == 0) putchar('+');
  103.                 printf("%s", v2[i].c_str());
  104.                 counter++;
  105.             }
  106.         }
  107.         if (counter != 0) putchar(10);
  108.  
  109.         counter = 0;
  110.         for (int i = 0; i < len; i++){
  111.             string lol = mp2[v[i]];
  112.             if (lol.length() == 0){
  113.                 printed = true;
  114.                 if (counter != 0) putchar(',');
  115.                 if (counter == 0) putchar('-');
  116.                 printf("%s", v[i].c_str());
  117.                 counter++;
  118.             }
  119.         }
  120.         if (counter != 0) putchar(10);
  121.  
  122.         counter = 0;
  123.         for (int i = 0; i < len; i++){
  124.             string lol = mp[v[i]];
  125.             string lol2 = mp2[v[i]];
  126.             if (lol.length() != 0 && lol2.length() != 0){
  127.                 if (strcmp(lol.c_str(), lol2.c_str()) != 0){
  128.                     printed = true;
  129.                     if (counter != 0) putchar(',');
  130.                     if (counter == 0) putchar('*');
  131.                     printf("%s", v[i].c_str());
  132.                     counter++;
  133.                 }
  134.             }
  135.         }
  136.         if (counter != 0) putchar(10);
  137.  
  138.         if (!printed) puts("No changes");
  139.         puts("");
  140.     }
  141.     return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement