codeforces 200 D Programming Language(stl)

来源:互联网 发布:筑巢软件上班怎么样 编辑:程序博客网 时间:2024/06/05 14:32

题意:

给出若干个函数声明,再给出若干变量定义,然后给出若干个函数调用,问每个调用有多少个声明的函数是符合这个调用的。


解题思路:

直接把非法字符变成空格然后用stringstream再读入一遍,这样处理字符串简直不能更方便,然后接下来的比较其实就很暴力了。


代码:

#include <bits/stdc++.h>#define ps push_backusing namespace std;struct node{    string name;    vector<string>type;}p[1005];map<string, string>mp;bool f(char x){    if((x<='z' && x>='a') || (x>='A' && x<='Z') || (x<='9' && x>='0'))return true;    return false;}int main(){    ios::sync_with_stdio(false);    cin.tie(0);    stringstream ss;    string str, word;    int i, j, n, m, k;    cin>>n;    getline(cin,str);    for(i=1; i<=n; i++)    {        ss.str("");        ss.clear();        getline(cin, str);        for(int i=0; i<(int)str.size(); i++)if(!f(str[i]))str[i]=' ';        ss.str(str);        ss>>word>>word;        p[i].name=word;        while(ss>>word)        {            p[i].type.ps(word);        }    }    cin>>m;    getline(cin, str);    string a, b;    for(i=1; i<=m; i++)    {        cin>>a>>b;        mp[b]=a;       }    cin>>k;    getline(cin, str);    int ans=0;    for(i=1; i<=k; i++)    {        ans=0;        ss.str("");        ss.clear();        getline(cin, str);        for(int i=0; i<(int)str.size(); i++)if(!f(str[i]))str[i]=' ';        ss.str(str);        ss>>p[0].name;        while(ss>>word)        {            word=mp[word];            p[0].type.ps(word);        }                for(int i=1; i<=n; i++)        {            if(p[0].name!=p[i].name)continue;            int is=1;            if(p[i].type.size()!=p[0].type.size())continue;            for(j=0; j<(int)p[i].type.size(); j++)            {                is&=(j<(int)p[0].type.size() && (p[i].type[j]=="T" ||  p[i].type[j]==p[0].type[j]));            }            ans+=is;        }        p[0].type.clear();        cout<<ans<<endl;    }}



原创粉丝点击