Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin(".in");
  7. ofstream fout(",out");
  8.  
  9. char C[501][21], S[256], sep[] = ".,?!:; -+=*&";
  10. int n, nre, V[501];
  11.  
  12. int main()
  13. {
  14. fin >> nre;
  15. fin.get();
  16. for( ; nre > 0; nre--)
  17. {
  18. fin.getline(S, 256);
  19. char *p = strtok(S, sep);
  20. while(p != NULL)
  21. {
  22. if(p[0] >= '0' && p[0] <= '9')
  23. {
  24. int x = 0;
  25. for(int i = 0; i < strlen(p); i++)
  26. x = 10 * x + p[i] - '0';
  27. p = strtok(NULL, sep);
  28. int poz = 0;
  29. for(int i = 1; i <= n; i++)
  30. if(strcmp(C[i], p) == 0)
  31. poz = i;
  32. if(poz == 0)
  33. {
  34. n++;
  35. strcpy(C[n], p);
  36. V[n] = x;
  37. }
  38. else V[poz] += x;
  39. }
  40. p = strtok(NULL, sep);
  41. }
  42. }
  43. for(int i = 1; i <= n; i++)
  44. for(int j = i + 1; j <= n; j++)
  45. if(V[i] < V[j])
  46. {
  47. swap(V[i], V[j]);
  48. swap(C[i], C[j]);
  49. }
  50. else
  51. {
  52. if(V[i] == V[j])
  53. if(strcmp(C[i], C[j]) > 0)
  54. swap(C[i], C[j]);
  55. }
  56. fout << n << endl;
  57. for(int i = 1; i <= n; i++)
  58. fout << C[i] << ' ' << V[i] << endl;
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement