Easy Coding Contest 12 - Editorial

All contest related discussion goes here. Both Dev Skill and Non Dev Skill contest related discussion is allowed. (But please keep the forum clean)

Easy Coding Contest 12 - Editorial

by BishalG » Mon Jun 12, 2017 5:31 pm

Contest Archive Link: https://devskill.com/ContestArchive/Con ... d4a7086716

Contest Rank List: https://devskill.com/home/contestrankli ... d4a7086716


Problem A: Change Case of Alphabet
Link: https://devskill.com/CodingProblems/ViewProblem/321
Problem Setter: Bishal Gautam

In this problem, you are asked to change the lowercase letter to uppercase and vice versa.
So, you can simply check the whether the case of letter is lowercase or uppercase and then based upon that
change the case of letter to another one. you can do these transformation by adding/subtracting 32 with ascii
values
. As ascii value of lowercase and uppercase letter differ by 32.


Problem B: The Largest Number
Link: http://devskill.com/CodingProblems/ViewProblem/217
Problem Setter: MD. Hasibul Hasan

The idea of the problem is very simple. If we can replace left most digits by highest digit, then we will get
largest number. The highest digit is 9. So, we will go through the number by checking its digits. If the
digit is less than 9 we will replace it with 9 until the replacement count is less than P
( Maximum Digit we can replace ).



Problem C: Math is Fun
Link: http://devskill.com/CodingProblems/ViewProblem/216
Problem Setter: Md.Ashraful Islam Shohag

In this problem, you are given a number containing exactly one alphabetic character. your task to
find out the shortest possible value of that alphabetic character for which the total number is divisible by 3.
Possible value should be 1 to 9. So, you can simply replace that particular character with numbers from
1 to 9, then check whether that number is divisible by 3 or not
.


Problem D: Game of MODs
Link: http://devskill.com/CodingProblems/ViewProblem/232
Problem Setter: Tanmoy Tapos Datta

This is a complete search problem. You need to generate all the numbers you can make by deleting K
digits then the answer will be the maximum and minimum among them.

No the question arise how to generate all the numbers. As we can see the range of N is 0 to (10^10)-1
so if we select all the position in different combination, then there will be (2^9)-1 different combinations.
You can use backtrack or bit-mask to generate all this numbers and store the numbers in two array.
for example the arrays are maxi[] and mini [] now, maxi[i]=x then it means that x is the maximum number
you can get from N after deleting i digits. And it's same as mini. after this prepossesses for each query you
need to output the value of maxi[k] and mini[k].


Problem E: Game Kufa
Link: http://devskill.com/CodingProblems/ViewProblem/229
Problem Setter: Pranta Sarker

In this problem, you have to find difference between the positions which is Shafi or Rafi turned to pick a maximum
number exist in the array and similarly you have to check weather it is a Prime or not.
Look, Shafi always turn first and then Rafi . So, every time you may pick the maximum value **until your array
size is not 0**, do summation of all positions where Shafi got the maximum value and similarly all positions where
Rafi got the maximum value..If there are more than one maximum element then leftmost will be choosen.
Find the difference between them. Finally, check it out that is it a Prime or not. If the difference is Prime then
Rafi will win otherwise Shafi will win, you should check the sample input output to print the solution.
As the summation of n over all games will be 10000, you can simply simulate the game procedure ,each
time finding maximum from left side and adding to respective player's summation. So, there will be total
n*(n+1)/2 iteration at max. Then, finally you should check the absolute differences between two
scores is prime or not. Hope you can do this easily in O( Sqrt(N) ) complexity.
User avatar
 
Posts: 43
Joined: Tue Jan 17, 2017 10:10 pm

Re: Easy Coding Contest 12 - Editorial

by arabin07 » Thu Jun 15, 2017 7:16 am

Code: Select all
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
   
    int T;
    scanf("%d\n",&T);
    int ans[T];
   
    char string[T][51];
   
   
    for (int i = 0; i<T; i++) {
       
        fgets(string[i], 50, stdin);
       
        unsigned long len = strlen(string[i]);
       
        for (int j = 0; j<len; j++) {
            char c = string[i][j];
            if (isalpha(c)) {
                for (int k = 1; k<10; k++) {
                    string[i][j] = k+'0';
                    long long val = atoll(string[i]);
                    if (!(val%3)) {
                        ans[i] = k;
                        break;
                    }
                }
                break;
            }
        }
    }
    for (int i = 0; i<T; i++) {
        printf("Case %d: %d\n",(i+1),ans[i]);
    }
   
    return 0;
}


Hello this is my code for the problem Math is fun and it gives W/A can anyone help me please
 
Posts: 5
Joined: Wed Jul 27, 2016 11:04 pm

Re: Easy Coding Contest 12 - Editorial

by BishalG » Thu Jun 15, 2017 10:00 am

@arabin07 , Here you are using builtin function "atoll" to convert string into long long integer. But, as the length of string could be upto 50.But, long long datatype does not support such a big integer. So, you are getting WA. Please try to find another way without converting string into integer number.
User avatar
 
Posts: 43
Joined: Tue Jan 17, 2017 10:10 pm

Re: Easy Coding Contest 12 - Editorial

by arabin07 » Sat Jun 17, 2017 2:46 am

Code: Select all
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
    int T;
    scanf("%d\n",&T);
    int ans[T];
    char string[T][51];
    for (int i = 0; i<T; i++) {
       
        fgets(string[i], 50, stdin);
       
        unsigned long size = strlen(string[i]);
       
        for (int j = 0; j<size; j++) {
           
            char c = string[i][j];
           
            if (isalpha(c)) {
               
                for (int k = 1; k<10; k++) {
                    string[i][j] = k+'0';
                   
                    if (size>18) {
                        unsigned long d = size/3;
                        char d1[d],d2[d],d3[d];
                        strncpy(d1, string[i], d);
                        strncpy(d2, &(string[i][d]), d);
                        strncpy(d3, &(string[i][2*d]), d);
                        long long dd1,dd2,dd3,sum;
                        //printf("%s , %s , %s",d1,d2,d3);
                        //break;
                        dd1 = atoll(d1);
                        dd2 = atoll(d2);
                        dd3 = atoll(d3);
                        //printf("%lld , %lld , %lld\n",dd1,dd2,dd3);
                        sum = dd1+dd2+dd3;
                        //printf("%lld\n",sum);
                        //break;
                        if (!(sum%3)) {
                            ans[i] = k;
                            //printf("divided by %d\n",k);
                            break;
                        }
                    }
                    else{
                        long long val = atoll(string[i]);
                        //printf("%lld\n",val);
                        if (!(val%3)) {
                            ans[i] = k;
                            break;
                        }
                    }
                   
                }
                break;
            }
           
        }
    }
    for (int i = 0; i<T; i++) {
        printf("Case %d: %d\n",(i+1),ans[i]);
    }
   
    return 0;
}

Hi @Bishal vai this code is for big numbers but still gives W/A can you can help me with that please
 
Posts: 5
Joined: Wed Jul 27, 2016 11:04 pm

Re: Easy Coding Contest 12 - Editorial

by BishalG » Wed Jun 21, 2017 2:53 pm

Hello @arabin07, The concept of adding 3 different integer is wrong.
You may see that "123456" !=(123)+(456).
User avatar
 
Posts: 43
Joined: Tue Jan 17, 2017 10:10 pm

Re: Easy Coding Contest 12 - Editorial

by BishalG » Wed Jun 21, 2017 2:57 pm

@arabin07, you may observe that , "123" = (1*100+2*10+3*1).
And, according to modular arithmetic, you may apply modulus operation between "*" and "+" easily.
so, it will be same as: 123%3 = (1*100+2*10+3*1)%3 = ( (1*100)%3 + (2*10)%3 + (3*1)%3 )%3.
User avatar
 
Posts: 43
Joined: Tue Jan 17, 2017 10:10 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron