[ create a new paste ] login | about

Link: http://codepad.org/jrOh8l8H    [ raw code | output | fork ]

C++, pasted on Dec 10:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cctype>

void io_partline_end(std::ostream& _out, std::istream& _in, int (*cmp)(int)){
	int i, j;
	std::string s;
	while(std::getline(_in, s) && !_in.fail()){
		j = (int)s.length() - 1;
		for(i = j; i >= 0; --i){
			if((*cmp)(s[i])){
				for(int p = i; p < j; ++p)
					std::swap(s[p], s[p + 1]);
				--j;
			}
		}
		_out << s << std::endl;
	}
	_out.flush();
}

int main(void){
	char s[] = "1C2O3B4O5L6 L7I8S9P \n\n1APL 0001D \n2012FORTH-";
	std::istringstream sp(s);
	io_partline_end(std::cout, sp, isdigit);

/*  работа с файлом
	std::ifstream fin("input.txt");
	std::ofstream fout("output.txt");
	io_partline_end(fout, fin, isdigit);
	fin.close();
	fout.close();
*/
	return 0;
}


Output:
1
2
3
4
COBOL LISP 123456789

APL D 10001
FORTH-2012


Create a new paste based on this one


Comments: