algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

main.cpp (1732B)


      1 #include <iostream>
      2 #include <vector>
      3 #include <unordered_set>
      4 #include <unordered_map>
      5 #include <algorithm>
      6 #include <queue>
      7 
      8 #define ll long long
      9 
     10 using namespace std;
     11 
     12 
     13 //- p, q strings
     14 //- p as product of variables written in the numerator of a fraction
     15 //- q as product of variables written in the denominator of a fraction
     16 //- can we mutate this such that the numerator simplified to "six" and denominator is cleared?
     17 //    - return YES / NO
     18 
     19 // NOTE: Char order doesn't matter because multiplication is associative.
     20 
     21 int main() {
     22 
     23     int testCases, current, pSize, qSize;
     24     string p, q = "";
     25 
     26     cin >> testCases;
     27 
     28     // idea:
     29         // put into hashmap, count numbers, ensure sDelta = 1, iDelta = 1, xDelta = 1, all rest = 0
     30 
     31     for(int z = 0; z < testCases; ++z) {
     32         cin >> pSize;
     33         cin >> qSize;
     34         cin >> p;
     35         cin >> q;
     36 
     37         vector<int> pCharCounts (26,0);
     38 
     39         for(int i = 0; i < pSize; ++i) {
     40             pCharCounts[p[i] - 'a'] += 1;
     41         }
     42 
     43         for(int i = 0; i < qSize; ++i) {
     44             pCharCounts[q[i] - 'a'] -= 1;
     45         }
     46 
     47         int sum = 0;
     48         bool printed = false;
     49         for(int i = 0; i < 26; ++i) {
     50             if(pCharCounts[i] < 0) {
     51                 cout << "NO" << endl;
     52                 printed = true;
     53                 break;
     54             }
     55             sum += pCharCounts[i];
     56         }
     57 
     58         if(printed) {
     59             continue;
     60         }
     61         
     62         if(sum != 3) {
     63             cout << "NO" << endl;
     64         }
     65         else if(pCharCounts['s' - 'a'] == 1 && pCharCounts['i' - 'a'] == 1 && pCharCounts['x' - 'a'] == 1) {
     66             cout << "YES" << endl;
     67         }
     68         else {
     69             cout << "NO" << endl;
     70         }
     71         
     72 
     73     }
     74 
     75 }