Created
September 25, 2011 22:20
-
-
Save emtwo/1241251 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <stdio.h> | |
using namespace std; | |
int main() { | |
char ch1, ch2; | |
cin.get(ch1); | |
for (;;) { | |
if (cin.fail()) break; | |
if (ch1 == '\n') cout << ch1; | |
if(ch1 == ' ' || ch1 == '\t' || ch1 == '\n') { | |
cin.get(ch1); | |
continue; | |
} else { | |
cout << ch1; | |
cin.get(ch2); | |
if (ch2 == '\t') ch2 = ' '; | |
} | |
for (;;) { | |
ch1 = ch2; | |
cin.get(ch2); | |
if (ch2 == '\t') ch2 = ' '; | |
if (ch1 == ' ' && ch2 == ' ') { | |
continue; | |
} | |
else if (ch1 == ' ' && ch2 == '\n') { | |
cout << ch2; | |
break; | |
} else if (ch1 == '\n') { | |
cout << ch1; | |
ch1 = ch2; | |
break; | |
} else { | |
cout << ch1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment