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.52 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("cadouri.in");
  7. ofstream fout("cadouri.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. {
  46. if(V[i] < V[j])
  47. {
  48. swap(V[i], V[j]);
  49. swap(C[i], C[j]);
  50. }
  51. else
  52. if(V[i] == V[j])
  53. {
  54. if(strcmp(C[i], C[j]) > 0)
  55. swap(C[i], C[j]);
  56. }
  57. }
  58.  
  59.  
  60. fout << n << endl;
  61. for(int i = 1; i <= n; i++)
  62. fout << C[i] << ' ' << V[i] << endl;
  63.  
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement