M - Gitignore

题目链接
把不能忽略的文件路径记录一下,再从可以忽略的文件里遍历,遇到可以忽略的文件就删除,后面遇到相同路径的文件就不用操作了。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define ll long long
using namespace std;
map<string,int>mp;
map<string,int>vis;


int main()
{
   ios::sync_with_stdio(false);
   int t,n,m;
   cin>>t;
   while(t--)
   {
       vis.clear();
       mp.clear();
       cin>>n>>m;
       string del,non_del;
       vector<string>s[1005];
       string str;
       for(int i=0; i<n; i++)
       {
           int len;
           cin>>del;
           len = del.size();
           str.clear();
           for(int j=0; j<len; j++)
           {
               if(del[j]!='/')
                   str+=del[j];
               else
               {
                   str+='/';
                   s[i].push_back(str);
               }
               if(j==len-1)
               {
                   s[i].push_back(str);
               }
           }
       }
       for(int i=0; i<m; i++)
       {
            cin>>non_del;
            str.clear();
            for(int j=0; j<non_del.size(); j++)
            {
                if(non_del[j]!='/')
                    str+=non_del[j];
                else
                {
                    str+='/';
                    mp[str] = 1;
                }
                if(j==non_del.size()-1)
                {
                    mp[str] = 1;
                }
            }
       }
       int ans=0;
       for(int i=0; i<n; i++)
       {
           for(int j=0; j<s[i].size(); j++)
           {
               if(vis[s[i][j]])
                   break;
               else
               {
                   if(mp[s[i][j]])
                   {
                       continue;
                   }
                   else
                   {
                       vis[s[i][j]] = 1;
                       ans++;
                       break;
                   }
               }
           }
       }
       cout<<ans<<endl;
   }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值