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; }
Input
A._ B.__ C.____ D.________
strlen() of A is 1, B is 2, C is 4, D is 8. that is tricky ;)
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