giabinh

10507_WakeUpBrain

Aug 23rd, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <bits/stdc++.h>;
  2.  
  3. //#define maxA 30
  4.  
  5. using namespace std;
  6.  
  7. int a[30][30], ke[30];
  8. int n, m;
  9.  
  10. void connect(char c) {
  11.     for (int i=1; i<27; ++i)
  12.         a[i][c - 'A' + 1] = a[c - 'A' + 1][i] = 1;
  13.     ke[c] = 30;
  14. }
  15.  
  16. int main() {
  17.     #ifndef ONLINE_JUDGE
  18.         freopen("uva10507.inp", "r", stdin);
  19.     #endif // ONLINE_JUDGE
  20.  
  21.     while (1) {
  22.         n = m = 0;
  23.         scanf("%d%d", &n, &m); //cout << n << " " << m << endl;
  24.         if (n == 0) break;
  25.         memset(a, 0, sizeof(a));
  26.         memset(ke, 0, sizeof(ke));
  27.         int years = 0;
  28.         string s; getline(cin, s);
  29.  
  30.         getline(cin, s);
  31.         int len = s.length(); //cout << s << endl;
  32.         for (int i=0; i<len; ++i) connect(s[i]);
  33. /*
  34.         for (int i=1; i<27; ++i) {
  35.             for (int j=1; j<27; ++j) cout << a[i][j] << " ";
  36.             cout << endl;
  37.         }
  38. */
  39.         for (int i=0; i<m; ++i) {
  40.             string s; getline(cin, s); cout << s[0] << " " << s[1] << " ";
  41.             a[s[0] - 'A' + 1][s[1] - 'A' + 1] = a[s[1] - 'A' + 1][s[0] - 'A' + 1] = 1;
  42.             ++ke[s[0] - 'A' + 1]; ++ke[s[1] - 'A' + 1]; cout << ke[s[0] - 'A' + 1] << " " << ke[s[1] - 'A' + 1] << endl;
  43.             if (ke[s[0] - 'A' + 1] >= 3 && ke[s[0] - 'A' + 1] < 30)  { connect(s[0]); ++years; }
  44.             if (ke[s[1] - 'A' + 1] >= 3 && ke[s[1] - 'A' + 1] < 30)  { connect(s[1]); ++years; }
  45.         }
  46.  
  47.         if (!years) printf("THIS BRAIN NEVER WAKES UP");
  48.         else printf("WAKE UP IN, %d, YEARS", years);
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment