当前位置:网站首页>Zhinai's database

Zhinai's database

2022-06-25 06:24:00 CTGU-Yoghurt

Topic link : Sign in — major IT Written interview preparation platform _ Cattle from


Ideas :

Put the serial number of the type to be marked in each row

Put together to form a string

Traverse each row

The number of string types in this row is changed each time ++

The number of output categories is the categories that can be divided according to the requirements of the topic

Then output the previous statistics in turn

Number of different kinds of concatenated strings

This is the positive solution


Code details :

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[1010][1010];
string s[1010];
map<string,int>mp,p;
string g;
vector<int> f;
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>s[i],p[s[i]]=i;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    getchar();
    getline(cin,g);
    int o=36;
    for(int i=36;i<=g.length();i++)
        if(g[i]==','||g[i]==';')
            f.push_back(p[g.substr(o,i-o)]),o=i+1;// Count the character segments to be distinguished 
    for(int i=1;i<=n;i++)
    {
        string s;
        for(int j=0;j<f.size();j++)
        {
            s=s+to_string(a[i][f[j]]);// Add the character segments to be distinguished , Form new characters 
        }
        mp[s]++;// For the composed array ++( Play the role of counting the same array )
    }
    cout<<mp.size()<<endl;
    for(auto x:mp)
        cout<<x.second<<" ";// Output mp The number of different types in each array 
}

PS: Clouds want clothes, flowers want looks , The spring breeze blows over Revlon .____ Li Bai 《 Qing pingdiao · firstly 》

原网站

版权声明
本文为[CTGU-Yoghurt]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202201233066518.html