Monday, June 2, 2014

Codeforces Round #250 (Div. 2), problem: (A) The Child and Homework solution

Codeforces Round #250 (Div. 2), problem: (A) The Child and Homework: http://codeforces.com/contest/437/problem/A

Codeforces Round #250 (Div. 2), problem: (A) The Child and Homework editorial: http://codeforces.com/blog/entry/12513

Codeforces Round #250 (Div. 2), problem: (A) The Child and Homework solution: http://ideone.com/G7cPqT

#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>

using namespace std;

int main() {
    int mi=INT_MAX, ma=0, ri, ra, cnti=0, cnta=0;
    char s[5][105];
    for(int i=0; i<4; i++) scanf("%s", s[i]);
    for(int i=0; i<4; i++) {
        if(strlen(s[i])-2<mi) mi=strlen(s[i])-2, ri=i;
    }
    for(int i=0; i<4; i++) if(mi<=(strlen(s[i])-2)/2) cnti++;
    for(int i=0; i<4; i++) {
        if(strlen(s[i])-2>ma) ma=strlen(s[i])-2, ra=i;
    }
    for(int i=0; i<4; i++) if(ma>=(strlen(s[i])-2)*2) cnta++;
    if(cnti>=3 && cnta>=3) printf("%c", s[2][0]); 
    else if(cnti>=3) printf("%c", s[ri][0]);
    else if(cnta>=3) printf("%c", s[ra][0]);
    else printf("%c", s[2][0]);
    return 0;
}

note: i dont know why, INT_MIN in <climits> does not work properly. i assigned ma=INT_MIN, that did not work so i changed it to 0. btw, be careful with input:
Input
A._
B.__
C.____
D.________

strlen() of A is 1, B is 2, C is 4, D is 8. that is tricky ;)

1 comment:

  1. strlen() returns an unsigned. When you compare INT_MIN with a unsigned, the implicit conversion makes it a quite large unsigned. This is why it is not "working properly".

    ReplyDelete