CodeChef submission 270509 (C) plaintext list. Status: WA, problem WORDS1, contest . By prajata (prajata), 2010-06-18 20:43:31.
#include<stdio.h> #include<stdlib.h> int main() { int source[26],dest[26],same[26],i,j,no_of_tests,no_of_words,count,count1,count2; char str[5],start,end; for(i=1;i<=no_of_tests;i++) { count=0; count1=0; count2=0; fread(str,1,1,stdin); // done 2 eat up the line feed for(j=0;j<26;j++) { source[j]=0; dest[j]=0; same[j]=0; } for(j=1;j<=no_of_words;j++) { fread(str,1,1,stdin); start=str[0]; while(str[0]>='a'&& str[0]<='z') { end=str[0]; fread(str,1,1,stdin); } if(start==end) same[start-'a']=1; else { source[start-'a']++; dest[end-'a']++; } } for(j=0;j<26;j++) { if(same[j]) { if(source[j]) { same[j]--; source[j]--; } else if(dest[j]) { dest[j]--; same[j]--; } } if(source[j]>dest[j]) { source[j]-=dest[j]; dest[j]=0; } else { dest[j]-=source[j]; source[j]=0; } } for(j=0;j<26;j++) { if(same[j]) count++; } if(count>1) { continue; } if(count) { for(j=0;j<26;j++) { if(source[j]!=0||dest[j]!=0) break; } if(j==26) { continue; } continue; } for(j=0;j<26;j++) { count1+=source[j]; count2+=dest[j]; } if((count1==1&&count2==1)||(count1==0&&count2==0)) { continue; } } return 0; }
Comments

