Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- using namespace std;
- ifstream fin(".in");
- ofstream fout(",out");
- char C[501][21], S[256], sep[] = ".,?!:; -+=*&";
- int n, nre, V[501];
- int main()
- {
- fin >> nre;
- fin.get();
- for( ; nre > 0; nre--)
- {
- fin.getline(S, 256);
- char *p = strtok(S, sep);
- while(p != NULL)
- {
- if(p[0] >= '0' && p[0] <= '9')
- {
- int x = 0;
- for(int i = 0; i < strlen(p); i++)
- x = 10 * x + p[i] - '0';
- p = strtok(NULL, sep);
- int poz = 0;
- for(int i = 1; i <= n; i++)
- if(strcmp(C[i], p) == 0)
- poz = i;
- if(poz == 0)
- {
- n++;
- strcpy(C[n], p);
- V[n] = x;
- }
- else V[poz] += x;
- }
- p = strtok(NULL, sep);
- }
- }
- for(int i = 1; i <= n; i++)
- for(int j = i + 1; j <= n; j++)
- if(V[i] < V[j])
- {
- swap(V[i], V[j]);
- swap(C[i], C[j]);
- }
- else
- {
- if(V[i] == V[j])
- if(strcmp(C[i], C[j]) > 0)
- swap(C[i], C[j]);
- }
- fout << n << endl;
- for(int i = 1; i <= n; i++)
- fout << C[i] << ' ' << V[i] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement