Advertisement
apl-mhd

UVA 12626 I love pizza

Jul 7th, 2021
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <algorithm>
  4. using namespace  std;
  5.  
  6. int main() {
  7.  
  8.  
  9.     int  n;
  10.     cin>>n;
  11.     cin.ignore();
  12.     while (n--){
  13.         string stringLine;
  14.         map<char, int> charMap;
  15.  
  16.         cin>>stringLine;
  17.         int max = 0;
  18.         for (int i = 0; i <stringLine.size() ; ++i) {
  19.                 char t = stringLine[i];
  20.             if (t == 'M' || t=='A' || t=='R' || t=='G' || t=='I' || t=='T'){
  21.                 charMap[t] +=1;
  22.                 if (  charMap[t] > max )
  23.                      max = charMap[t];
  24.             }
  25.         }
  26.         int count =0;
  27.         if (charMap['A'] > 2 && charMap['R'] > 1 && charMap['M'] > 0
  28.         && charMap['G'] > 0 && charMap['T'] > 0 && charMap['I'] > 0) {
  29.             for (int i = 0; i < max; ++i) {
  30.                 bool flag = true;
  31.                 for (auto i = charMap.begin(); i != charMap.end(); ++i) {
  32.                     if (i->second != 0)
  33.                         charMap[i->first] -= 1;
  34.                     else
  35.                         flag = false;
  36.                 }
  37.  
  38.                 if (flag == true)
  39.                     count += 1;
  40.             }
  41.         }
  42.         cout<<count<<endl;
  43.  
  44.     }
  45.  
  46.  
  47.  
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement