CCF(元素选择器:50分):字符串+模拟

时间:2019-09-01
本文章向大家介绍CCF(元素选择器:50分):字符串+模拟,主要包括CCF(元素选择器:50分):字符串+模拟使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

元素选择器

201809-3

这里我只考虑了没有后代选择器的情况

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
string s[101];
int n,m;
int main(){
    cin>>n>>m;
    getchar();
    for(int i=0;i<n;i++){
        getline(cin,s[i]);
    }
    for(int i=0;i<m;i++){
        string ss;
        getline(cin,ss);
        int ans=0;//记录出现次数
        int row[101];
        for(int i=0;i<n;i++){//每一行查询
            stringstream sss(s[i]);
            if(ss[0]=='#'){//这是属性
                string temp;
                sss>>temp;
                sss>>temp;
                if(temp==ss){
                    row[ans++]=i+1;
                }
            }else{//这是标签
                string temp;
                sss>>temp;
                string now="";
                for(int j=0;j<temp.length();j++){
                    if(temp[j]!='.'){
                        if(temp[j]<='Z'&&temp[j]>='A')
                            now+=temp[j]-'A'+'a';
                        else{
                            now+=temp[j];
                        }
                    }
                }
                string now1="";
                for(int j=0;j<ss.length();j++){
                    if(ss[j]<='Z'&&ss[j]>='A')
                        now1+=ss[j]-'A'+'a';
                    else{
                        now1+=ss[j];
                    }
                }
                if(now==now1){
                    row[ans++]=i+1;
                }
            }
            sss.str("");
        }
        cout<<ans;
        for(int j=0;j<ans;j++){
            cout<<" "<<row[j];
        }
        cout<<endl;
    }
    //system("pause");
    return 0;
}

原文地址:https://www.cnblogs.com/GarrettWale/p/11441894.html