top of page

CCC '24 J4 - Troublesome Keys

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
   string ps;
   string ds;
   cin >> ps;
   cin >> ds;
   string first_p = "";
   string first_d ="";
   string second_p = "";
   bool has_first = false;
   bool has_second = false; 

   int i = 0;
   int j = 0;

   while(i < ps.size()){
      if(j < ds.size() && ps[i] == ds[j]){
         i++;
         j++;
      }
      else if(j >= ds.size()){
          second_p += ps[i];
          break;
      }
      else{
         if(has_first == false && has_second == false){
            if(i+1 >= ps.size() || ps[i] == ps[i+1] || (ps[i+1] == ds[j+1] && ps[i+1]!=ds[j])){
               first_p += ps[i];
               first_d += ds[j];
               has_first = true;
               i++;
               j++;
            }
            else{
               second_p += ps[i];
               has_second = true;
               i++;
            }
         }
         else if(has_first == true && has_second == false){
            if(ps[i] != first_p[0]){
              second_p += ps[i];
              break;
            }
            else{
               i++;
               j++;
            }
         }
         else if(has_first == false && has_second == true){
            if(ps[i] != second_p[0]){
               first_p += ps[i];
               first_d += ds[j];
               break;
             }
             else{
               i++;
             }
        }
        else{
            break;
        }
      }
   }
   
   std::cout<<first_p<<" "<<first_d<<endl;
   
   if(second_p.size() == 0){
      std::cout<<"-"<<endl;
   } 
   else{
      std::cout<<second_p<<endl;
   }

}

Recent Posts

See All

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c, sr, sc; cin >> r; cin >> c; int p[r][c]; bool v

CCC '22 J5 - Square Pool

#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool rowcom(pair<int, int> a, pair<int, int> b){ return a.first < b.first; } bool colcom(pair<int,

CCC 2013 J5/S3

#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cmath> using namespace std; char itlist[3] = {'W','L','T'}; int num_of_games_left = 0; int resul

Comments


bottom of page