cpp
Wednesday, February 22, 2006
/*
VALUE
NAME
*/
#include
#include
#include
#include
using namespace std;
map
summary;
map
counter;
enum Sign{ NAME, NUMBER, NIHIL};
Sign current_sign = NIHIL;
double number_value;
string c_name;
void store_values()
{
summary[c_name] += number_value;
counter[c_name] += 1;
}
Sign get_char()
{
char ch = 0;
cin >> ch;
if( isspace(ch) )
{
switch( current_sign )
{
case NIHIL:
return current_sign;
case NUMBER:
current_sign = NIHIL;
store_values();
return current_sign;
case NAME:
c_name += ch;
return current_sign;
default:
return current_sign;
}
}
switch(ch)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '.':
if ( current_sign == NIHIL ) return current_sign;
current_sign = NUMBER;
cin.putback(ch);
cin>>number_value;
break;
default:
if ( isalpha(ch) )
{
switch (current_sign)
{
case NIHIL:
current_sign = NAME;
c_name = ch;
return current_sign;
case NUMBER:
current_sign = NAME;
store_values();
c_name = ch;
return current_sign;
default:
return current_sign;
}
}
return current_sign;
}
}
void print( const pair
& r )
{
cout << r.first << r.second << '\n';
}
int main()
{
while (cin)
{
get_char();
}
for_each( summary.begin(), summary.end(), print );
return 0;
}
posted by tyrkisk at
2:10 PM
0 comments
Links
Google News
Edit-Me
Edit-Me
Previous Posts
sdl input handlingwhile (Running) eating up proces...
if ((Grid[id[0]] != GRID_TYPE_NONE)&& (...
templates
making command line option parsing
about the usage of cvs
/* VALUE NAME*/#include#include#include#includeusi...
Archives
February 2006
May 2006
June 2006
August 2006
November 2011
December 2011