|
|
back to boardWA 5 Posted by Evgeny 23 Sep 2011 00:38 I've got WA #5. Help me, please! #include <string.h> #include <iostream> int main(int argc, char* argv[]) { char s[51]; int a[26]; for(int i=0;i<26;i++) a[i] = 0; std::cin>>s; for(int i=0;i<strlen(s);i++) (a[(int)(s[i]) - 91])++; int max = 0; bool g = false; for(int i=0; i<26; i++) if (max<a[i]) { max = a[i]; } for(int i=0;i<strlen(s);i++) if(a[(int)(s[i]) - 91] == max) { g=true; std::cout<< s[i]; a[(int)(s[i]) - 91] = -1; } else if (g) { break; } std::cout<<"\n"; return 0; } Edited by author 23.09.2011 00:42 Edited by author 23.09.2011 00:43 Re: WA 5 Posted by Evgeny 23 Sep 2011 12:26 I read ASCII table and got AC! #include <string.h> #include <iostream> int main(int argc, char* argv[]) { char s[51]; int a[26],k=0; for(int i=0;i<26;i++) a[i] = 0; std::cin>>s; for(int i=0;i<strlen(s);i++) (a[(int)(s[i]) - 97])++; int max = 0; for(int i=0; i<26; i++) if (max<a[i]) { max = a[i]; k=i; } k+=97; std::cout<<(char)(k) <<std::endl; return 0; } Re: WA 5 Hello, I did in the similar way, then I got a matrix, I tied to find the longest string from the matrix.But at this point I saw your post, and just tried printing the maximum repeated character like you have done.But how does that work, even it returns wrong answer for the first test.Can't understand. Please give me some suggestions.
|
|
|