Skip to main content
  1. Problem Solving Solutions/

Chef and Card Game CodeChef Solution

·1 min
codechef-solutions
Mayukh Datta
Author
Mayukh Datta
Table of Contents

Problem: https://www.codechef.com/JULY20B/problems/CRDGAME

Solution in C++ #

#include<bits/stdc++.h> using namespace std; #define MAX 1000000

int sum_of_digits(int n) { int sum = 0;

while(n != 0) {
    sum += n % 10;
    n = n / 10;
}
return sum;

}

int main() { int t, n; int chef_card, morty_card;

cin >> t;

while(t--) {
    cin >> n;

    int chef\_score = 0, morty\_score = 0;

    for(int i=0;i<n;i++) {
        cin >> chef\_card >> morty\_card;

        int sum\_chef = sum\_of\_digits(chef\_card);
        int sum\_morty = sum\_of\_digits(morty\_card);

        if(sum\_of\_digits(chef\_card) > sum\_of\_digits(morty\_card)) {
            chef\_score++;
        }else if(sum\_chef < sum\_morty){
            morty\_score++;
        }else{
            chef\_score++;
            morty\_score++;
        }
    }

    if(chef\_score > morty\_score) {
        printf("0 %d\\n", chef\_score);
    }else if(morty\_score > chef\_score) {
        printf("1 %d\\n", morty\_score);
    }else if(chef\_score == morty\_score) {
        printf("2 %d\\n", chef\_score);
    }
}

return 0;

}