Skip to main content

solution : Another Card Game Problem | codechef | Problem Code: CRDGAME3

 

Another Card Game Problem Problem Code: CRDGAME3

Chef is playing a card game with his friend Rick Sanchez. He recently won against Rick's grandson Morty; however, Rick is not as easy to beat. The rules of this game are as follows:

  • The power of a positive integer is the sum of digits of that integer. For example, the power of 13 is 1+3=4.
  • Chef and Rick receive randomly generated positive integers. For each player, let's call the integer he received final power.
  • The goal of each player is to generate a positive integer such that its power (defined above) is equal to his final power.
  • The player who generated the integer with fewer digits wins the game. If both have the same number of digits, then Rick cheats and wins the game.

You are given the final power of Chef PC and the final power of Rick PR. Assuming that both players play optimally, find the winner of the game and the number of digits of the integer he generates.

Input

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains two space-separated integers PC and PR.

Output

For each test case, print a single line containing two space-separated integers. The first of these integers should be either 0 if Chef wins or 1 if Rick wins. The second integer should be the number of digits of the integer generated by the winner.

Constraints

  • 1T105
  • 1PC,PR106

Subtasks

Subtask #1 (100 points): original constraints

Sample Input 1 

3
3 5
28 18
14 24

Sample Output 1 

1 1
1 2
0 2

Explanation

Example case 1: Chef and Rick generate the optimal integers 3 and 5 respectively. Each of them has 1 digit, so Rick cheats and wins the game.

Example case 2: Chef and Rick could generate e.g. 6877 and 99 respectively. Since Rick's integer has 2 digits and Chef cannot generate an integer with less than 4 digits, Rick wins.

Example case 3: Chef and Rick could generate e.g. 86 and 888 respectively. Chef's integer has 2 digits and Rick cannot generate an integer with less than 3 digits, so Chef wins.


solution : 


#include <iostream>

using namespace std;


int main() {

long long int t;

cin >> t;

while(t--)

{

     long long int pc , pr ;

     cin >> pc >> pr ;

     int first_int , second_int ;

      first_int = (pc/9) < (pr/9) ? 0 : 1 ;

      if(pc < 10 || pr < 10)

      {

         second_int = 1;

           

      }

      else

      {

      second_int = (pc/9) < (pr/9) ? (((pc%9)==0)?(pc/9):(pc/9)+1) : (((pr%9)==0)?(pr/9):(pr/9)+1)  ;

      }

     cout << first_int << " "<< second_int << "\n" ;

}

return 0;

}

if you have any problem regarding solution , you can comment below.


Comments

Popular posts from this blog

leetcode 48 solution

  48 .  Rotate Image You are given an  n x n  2D  matrix  representing an image, rotate the image by  90  degrees (clockwise). You have to rotate the image  in-place , which means you have to modify the input 2D matrix directly.  DO NOT  allocate another 2D matrix and do the rotation.   Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[7,4,1],[8,5,2],[9,6,3]] Example 2: Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]   Constraints: n == matrix.length == matrix[i].length 1 <= n <= 20 -1000 <= matrix[i][j] <= 1000 solution: class Solution { public:     void swap(int& a , int &b)     {         int c ;         c = a;         a = b;         b = c;     }     void transpose (vector<vector<int>...

Regular Expression Matching Leetcode Solution

Regular Expression Matching Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: '.' Matches any single character.​​​​ '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). Example 1: Input: s = "aa", p = "a"  Output: false  Explanation: "a" does not match the entire string "aa". Example 2: Input: s = "aa", p = "a*"  Output: true  Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa". Example 3: Input: s = "ab", p = ".*"  Output: true  Explanation: ".*" means "zero or more (*) of any character (.)". Constraints: 1 <= s.length <= 20 1 <= p.length <= 20 s contains only lowercase English letters. p contains only lowercase Englis...

2485. Find the Pivot Integer | Binary search

  Given a positive integer   n , find the   pivot integer   x   such that: The sum of all elements between  1  and  x  inclusively equals the sum of all elements between  x  and  n  inclusively. Return  the pivot integer  x . If no such integer exists, return  -1 . It is guaranteed that there will be at most one pivot index for the given input.   Example 1: Input: n = 8 Output: 6 Explanation: 6 is the pivot integer since: 1 + 2 + 3 + 4 + 5 + 6 = 6 + 7 + 8 = 21. Example 2: Input: n = 1 Output: 1 Explanation: 1 is the pivot integer since: 1 = 1. Example 3: Input: n = 4 Output: -1 Explanation: It can be proved that no such integer exist.   Constraints: 1 <= n <= 1000 Solution : class Solution { publ ic:     int pivotInteger( int n ) {         int sum = (( n )*( n + 1 ))/ 2 ;         int i = 1 ;         int j =...