ccf(元素选择器)AC

201809-3
试题名称: 元素选择器
时间限制: 1.0s
内存限制: 256.0MB
问题描述:

ccf(元素选择器)AC_第1张图片
ccf(元素选择器)AC_第2张图片
ccf(元素选择器)AC_第3张图片
ccf(元素选择器)AC_第4张图片

 

在考试的时候没有写出来...

后来一直很怕这道题,可是今天才发现我原来和解出这道题只差一点点.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

struct Node{
	int no;
	string label;
	string id;
};

//变成小写
string tolow(string s)
{
	for(int i = 0;i&v) 
{
	v.clear();
	char * p = strtok(s," ");
	while(p)
	{
		v.push_back(p);
		p = strtok(NULL," ");
	}
}


vectordemands;//命令 
mapan;//祖先的label和id,   以及命令中要求的段数 

int main() {
	//行数
	int n,m; 
	//变量 
	int i;
	char c;
	//放置数组
	vectornodes; 
	//读入行数 
	cin>>n>>m;
	getchar();
	for(i = 0;i>tid;
				getchar();
				temp.id = c+tid;
				break;
			}
			else//label
			{
				tlabel+=c;
				while((c=getchar())!=' ')
				{
					if(c=='\n')
					{
						flag = 1;
						break;
					}
					tlabel+=c;
				}
				temp.label = tolow(tlabel);
			}
			if(flag) break;
		}
		temp.no = tno/2;
		nodes.push_back(temp);
		//cout<ans;//保存行数 
		gets(d);
		split(d,demands);
		//全部id变小写
		for(int i = 0;i=0&&nodes[j].no<=nodes[i].no;j--)
					{
						if(nodes[j].no

世界上最可怕的事情应该就是妄自菲薄了吧.

高估自己能力什么的,起码还是有干劲的.

AC了.


我有毒。

我今天又写了一遍。

我今天神志有点不清醒,写完发现我的代码离上次的差好远,一点也不优雅。

果然人家的代码结构超好的。

要向人家学习~

#include 
#include 
using namespace std;
struct Node
{
    int num;
    string label;
    string id;
};
int n,m;
vectornodes;
vectorre;


string toLower(string label)//为了把字符串变成小写,因为label对大小写不敏感
{
    for(int i = 0;i='A'&&label[i]<='Z')
        {
            int num = label[i]-'A';
            label[i] = num + 'a';
        }
    }
    return label;
}


void split(string t)   //分割字符串
{
    int i;
    int pos1 = 0,pos2 = 0;
    while((pos2 = t.find(' ',pos1))!=string::npos)
    {
        string s = t.substr(pos1,pos2-pos1);
         s = toLower(s);
        re.push_back(s);
        pos1 = pos2+1;
    }
    string s = t.substr(pos1,t.length()-pos1);
    if(s[0] != '#')    //label是大小写不敏感的
        s = toLower(s);
    re.push_back(s);
}


void reAns()
{
    int i,j,k;
    queuest;
    for(i = 0;i=0;j--)
            {
                if(t_num<0)//找完了退出
                {
                    break;
                }
                t1 = re[t_num];
                if(nodes[j].num<=nodes[i].num)
                {
                    if(nodes[j].num=0) || !in)//全部规则都找遍了都没有找到,或者还有祖宗没有匹配.
            {
                flag = 1;
            }
            if(flag == 0)
                st.push(i+1);
        }
    }
    cout<>n>>m;
    getchar();
    for(i = 0; i

解释一下:

ccf(元素选择器)AC_第5张图片

因为我们是从下到上找的,先找最后一个选择器,如

div    div  p,那么先找到了p,我们希望是p的直系亲属匹配div,所以结构时这样的:

..

....

.......

...........

............

..............

而我们的p在最底层,如果是

.

.....

..

.........

那么就是有两层结构了,是两个家族.我们只在三角形里找,有平辈没有关系,但是祖宗不能有比自己长的.

你可能感兴趣的:(c++)