Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct inform {
- string miestas;
- string salis;
- int kiek;
- };
- inform A[300], B[300];
- void skaitymas(inform A[], int &n) {
- ifstream d("duom.txt");
- d >> n;
- d.ignore();
- char laik[21];
- for(int i = 1; i <= n; i++) {
- d.get(laik,21);
- A[i].miestas = laik;
- A[i].kiek = 1;
- B[i].kiek = 1;
- d >> A[i].salis;
- d.ignore();
- }
- d.close();
- }
- void atrinkti(inform A[], int &n, int &m, inform B[]) {
- bool yra;
- for(int i = 1; i <= n; i++) {
- yra = false;
- for(int j = 1; j <= m; j++){
- if(A[i].salis == B[j].salis) {
- yra = true;
- B[j].kiek++;
- }
- }
- if(!yra) {
- B[m].salis = A[i].salis;
- m++;
- }
- }
- for(int i = 1; i < m; i++) {
- cout << B[i].salis << " " << B[i].kiek << endl;
- }
- }
- int main() {
- int n = 1, m = 1;
- skaitymas(A,n);
- atrinkti(A,n,m,B);
- }
Advertisement
Add Comment
Please, Sign In to add comment