ouh.. and my input must be alphabet or alhabet+numeric only..
here what i did so far..
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <string>
- #include <map>
- using namespace std;
- class Cmp : public std::binary_function<std::string,std::string,bool> {
- public:
- bool operator()(const std::string& s1, const std::string& s2){ //????
- }
- };
- //typedef std::map<std::string, int, Cmp> MAP;
- typedef enum {s1, s2} STATUS;
- struct Count {
- int N;
- Count() : N(0) {}
- operator int() { return N; }
- void operator++() { N++; }
- };
- typedef map<string,Count> Map;
- int main(void){
- char c;
- map<string,Count> m;
- std::string buffer;
- STATUS status=s1;
- // while( cin >> str ) stringCounts[str]++;
- while(std::cin >> c){
- switch(status){
- case s1:
- if(isalpha(c)){
- // m[string]++;
- buffer=c;
- status=s2;
- }
- break;
- case s2:
- if(isalnum(c)){
- buffer+=c;
- }else{
- //std::cout << s1 << s2 << std::endl;
- std::cout << c << buffer << std::endl;
- status=s1;
- }
- break;
- }
- }
- if(status=s2){
- Map::iterator i = m.begin();
- while ( i != m.end() ) {
- cout << i->first << ':'
- << i->second << endl;
- ++i;
- std::cout << c << buffer << std::endl;
- }
- }
- return 0;
- }