bai tap

 avatar
NguyenAnhQuan
c_cpp
7 months ago
1.1 kB
7
Indexable
Never
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);  
    
    int cnt[100];
    memset(cnt, 0, sizeof(cnt));

    map <string, int> dem;

    cout << "nhap text case : ";
    int t; cin >> t;

    int tc = 0;
    while (t--)
    {
        int n;
        cout << "nhap so luong ten : "; cin >> n; 
        cout << "nhap danh sach " << ++tc << " : ";

        vector <string> s; 

        for (int i = 1; i <= n; i++)
        {
            string x; cin >> x;
            s.push_back(x);
        }

        cout << "nhap ten cua ban : "; 
        string y; cin >> y; s.push_back(y);

        for (int i = 0; i < (int)s.size(); i++)
        {
            dem[s[i]]++;
            cnt[i] = dem[s[i]];
        }

        for (int i = 0; i < (int)s.size(); i++)
            if (cnt[i] == 1 && dem[s[i]] == 1) cnt[i] = 0;

        for (int i = 0; i < (int)s.size(); i++)
            if (cnt[i] != 0) cout << s[i] << "." << cnt[i] << endl;
            else cout << s[i] << endl;
    
    }

    return 0;
}