MariusPure

miestai psl 112

Feb 27th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. struct inform {
  7. string miestas;
  8. string salis;
  9. int kiek;
  10. };
  11. inform A[300], B[300];
  12. void skaitymas(inform A[], int &n) {
  13. ifstream d("duom.txt");
  14.  
  15. d >> n;
  16. d.ignore();
  17. char laik[21];
  18.  
  19. for(int i = 1; i <= n; i++) {
  20. d.get(laik,21);
  21. A[i].miestas = laik;
  22. A[i].kiek = 1;
  23. B[i].kiek = 1;
  24. d >> A[i].salis;
  25. d.ignore();
  26. }
  27.  
  28. d.close();
  29. }
  30. void atrinkti(inform A[], int &n, int &m, inform B[]) {
  31. bool yra;
  32.  
  33. for(int i = 1; i <= n; i++) {
  34. yra = false;
  35. for(int j = 1; j <= m; j++){
  36. if(A[i].salis == B[j].salis) {
  37. yra = true;
  38.  
  39. B[j].kiek++;
  40. }
  41. }
  42. if(!yra) {
  43. B[m].salis = A[i].salis;
  44. m++;
  45. }
  46. }
  47. for(int i = 1; i < m; i++) {
  48. cout << B[i].salis << " " << B[i].kiek << endl;
  49. }
  50. }
  51.  
  52. int main() {
  53.  
  54. int n = 1, m = 1;
  55. skaitymas(A,n);
  56. atrinkti(A,n,m,B);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment