Created
July 29, 2011 02:34
-
-
Save smly/1113021 to your computer and use it in GitHub Desktop.
majority
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main() | |
| { | |
| char curr, next, ans; | |
| unsigned int cnt; | |
| for (curr = getchar();;curr = next) { | |
| if ((next = getchar()) == EOF || next == '\n') break; | |
| if (next == curr) { | |
| if (cnt == 0) ans = next; | |
| if (next == ans) { | |
| cnt++; | |
| } else { | |
| if (cnt > 0) cnt--; | |
| if (cnt == 0) ans = curr; | |
| } | |
| } | |
| } | |
| printf("Output: %c\n", (cnt > 0) ? ans : curr); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment