Advertisement
Guest User

GameOfThrones-I

a guest
Oct 17th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. unsigned int chars[26];
  6.  
  7. // Complete the gameOfThrones function below.
  8. string gameOfThrones(string s) {
  9.     bool jo = true;
  10.  
  11.     for(int i=0;i<s.length();i++){
  12.         chars[s[i]-'a']++;
  13.     }
  14.  
  15.     if(s.length()%2==0)
  16.     {
  17.         for(int i=0;i<26 && jo; i++){
  18.             if(chars[i]%2!=0)
  19.                 jo = false;
  20.         }
  21.     }
  22.     else
  23.     {
  24.         bool voltPrtln = false;
  25.  
  26.         for(int i=0; i<26; i++)
  27.         {
  28.             if(chars[i]%2!=0)
  29.             {
  30.                 if(!voltPrtln)
  31.                 {
  32.                     voltPrtln=true;
  33.                 }
  34.                 else
  35.                 {
  36.                     jo=false;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.  
  42.  
  43.     return jo ? "YES" : "NO";
  44. }
  45.  
  46. int main()
  47. {
  48.     ofstream fout(getenv("OUTPUT_PATH"));
  49.  
  50.     string s;
  51.     getline(cin, s);
  52.  
  53.     string result = gameOfThrones(s);
  54.  
  55.     fout << result << "\n";
  56.  
  57.     fout.close();
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement