icpc上海m题,错误代码,求改

Your git project (you don't need to be familiar with git to solve this problem) has some files that should be ignored from synchronizing. You need to calculate the minimum number of lines needed for gitignore.

Formally, your project is a folder. A folder can have files and sub folders. There are no empty folders (i.e. folders without any files or sub folders inside). Initially, the git software will synchronize all the files in your project. However, you can specify some files and folders in the settings (which is called gitignore) to exclude them from synchronizing. For each line in gitignore, you can specify either a file or all the files in a folder. You can not ignore the whole project folder (i.e. an empty line in gitignore).

You are given paths for all the files in the project and whether they should be ignored or shouldn't. Your task is to calculate the minimum number of lines for gitignore.

Input

The input contains several test cases. The first line contains a single positive integer T

which is the number of test cases. For each test case, you are first given two non-negative numbers n and m. And then n non-empty lines of file paths that should be ignored, and m

non-empty lines of file paths that should not be ignored.

The paths are strings containing lower-cased English alphabets and slashes (’/’) only. Slashes are used to separate folders, sub folders and file name. For exapmle, “a/b/c/d” indicates folder “a” in the project folder, folder “b” in folder “a”, folder “c” in “b” and file “d” in folder “c”. All the paths are valid, specifically:

The path is non-empty and it always indicates a file (i.e. the path does not end with a slash).
The path does not start with a slash.
Folder names and file names are non-empty (i.e. there are no consecutive slashes).
File paths are always unique (i.e. all the paths in a test case are different).
In a folder, no sub folders and files share the same names. For example, there won't be two files "a/b/a" and "a/b/a/d" in one test case. However, files "a/b/a" and "a/b/b" are allowed.

1≤n+m≤100
holds and in the whole input there are no more than 1,000 characters in file paths (i.e. the sum of lengths of file path strings in the whole input file is no more than 1,000

).

Output

T

lines of non-negative integers, the minimum number of gitignore lines for each test case.
这是有问题的代码,,,,

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#include <vector>
using namespace std;
string x;
string y;
struct node
{
    int num;
    vector<string>gg;
} p[105],q[105];
char str[1005];
map<string,bool>mp,me;
int main()
{
    int t,n,m,i,j;
    scanf("%d",&t);
    while(t--)
    {
        mp.clear();
        me.clear();
        int sum=0;
        scanf("%d%d",&n,&m);
        for(i=0; i<n; i++)
        {
            x.clear();
            scanf("%s",str);
            int len=strlen(str);
            for(j=0; j<len; j++)
            {
                if(str[j]!='/')
                {
                    x+=str[j];
                }
                else
                {

                    p[i].gg.push_back(x);
                    x.clear();
                }
            }
            p[i].gg.push_back(x);

        }
        for(i=0; i<m; i++)
        {
            y.clear();
            scanf("%s",str);
            int len=strlen(str);
            for(j=0; j<len; j++)
            {
                if(str[j]!='/')
                {
                    y+=str[j];
                }
                else
                {

                    q[i].gg.push_back(y);
                    y.clear();
                }
            }
            q[i].gg.push_back(y);
        }

        for(i=0; i<m; i++)
        {
            int y=q[i].gg.size();
            for(j=0; j<y; j++)
            {
                mp[q[i].gg[j]]=1;
            }
        }
        for(i=0; i<n; i++)
        {
            int y=p[i].gg.size();
            for(j=0; j<y; j++)
            {
                if(mp[p[i].gg[j]]==0)
                {
                    if(me[p[i].gg[j]]==1)
                    {
                        break;
                    }
                    else
                    {
                        sum++;
                        me[p[i].gg[j]]=1;
                        break;
                    }
                }
            }

        }
        printf("%d\n",sum);
    }


}

难受的一下午,icpc上海站的m题,绞尽脑汁了,感觉自己把所有的情况全都考虑了(m的那一组全部标记1,然后判断n那一组,me记录是否已经删除,mp标记是否可以删除,救救弱鸡跪求)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

直接AC好吗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值