Skip to content

Instantly share code, notes, and snippets.

@emtwo
Created September 25, 2011 22:20
Show Gist options
  • Save emtwo/1241251 to your computer and use it in GitHub Desktop.
Save emtwo/1241251 to your computer and use it in GitHub Desktop.
#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