CCF201803-3 URL映射

仿照老师的写的,理解了好久

#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
bool match(string &s, string &t, bool flag)
{
	int lena = s.length(), lenb = t.length();
	int ps = 0, pt = 0;
	while (ps < lena&&pt < lenb)
	{
		if (s[ps] == t[pt]) {
			ps++; pt++;
		}
		else {
			if (s[ps] != '<') return false;
			if (s[ps+1] == 'i') {
				if (flag) cout << ' ';
				bool ok = false;
				while (pt < lenb&&isdigit(t[pt]))
				{
					if (t[pt] != '0') ok = true;
					if (flag) {
						if (ok) cout << t[pt];
					}
					pt++;
				}
				if (!ok) return false;
				ps += 5;
			}
			else if (s[ps + 1] == 's') {
				if (flag) cout << ' ';
				bool ok = false;
				while (pt < lenb&&t[pt] != '/') {
					ok = true;
					if(flag) cout << t[pt];
					pt++;
				}
				if (!ok) return false;
				ps += 5;
			}
			else if (s[ps + 1] == 'p') {
				if (flag) {
					cout << ' ';
					while (t[pt]) cout << t[pt++];
				}
				return true;
			}
		}
	}
	return pt == lenb && ps == lena;
}
int main()
{
	int n, m;
	cin >> n >> m;
	string txt[100 + 10], url, names[100 + 10];
	for (int i = 0; i < n; i++) cin >> txt[i] >> names[i];
	while (m--)
	{
		cin >> url;
		int i;
		for (i = 0; i < n; i++) {
			if (match(txt[i], url, false)) {
				cout << names[i];
				match(txt[i], url, true);
				cout << endl;
				break;
			}
		}
		if (i == n) cout << "404\n";
	}
	//system("pause");
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值