[ create a new paste ] login | about

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

C++, pasted on Dec 20:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
#include <map>


bool is_vowels(char ch){
	return (ch == 'e') || (ch == 'u') || (ch == 'i') || (ch == 'o') ||(ch == 'a'); 
}


void out(const std::pair<std::string, int> &rhs){
	std::cout << rhs.first << "\t " 
		<< rhs.second 
		<< " : "<< (rhs.first.size() - rhs.second) 
		<< std::endl;
}

int main(){
	std::string rhs = "Testing Line Andrew maaaax";
	std::stringstream ss(rhs);

	std::map<std::string, int> map;
	std::map<std::string, int>::iterator im, max;

	std::vector<std::string> res;
	std::vector<std::string>::iterator i;

	std::copy(std::istream_iterator<std::string>(ss),
		std::istream_iterator<std::string>(),
		std::back_inserter(res));
	i = res.begin();
	for(; i != res.end(); ++i)
		map[*i] = count_if((*i).begin(), (*i).end(), is_vowels);
	
	im = max = map.begin();
	for(; im != map.end(); ++im){
		out(*im);
		if((*im).second > (*max).second)
			max = im;
	}
	std::cout << "Max: \n";
	out(*max);
	return 0;
}


Output:
1
2
3
4
5
6
Andrew	 1 : 5
Line	 2 : 2
Testing	 2 : 5
maaaax	 4 : 2
Max: 
maaaax	 4 : 2


Create a new paste based on this one


Comments: