CCF201803-3 URL映射

博主分享了在解决CCF201803-3问题过程中,通过阅读海岛老师的博客从30分提高到80分,最终AC的经历。文章特别提到使用C库函数isdigit()的重要性,并向海岛老师表达了敬意。
摘要由CSDN通过智能技术生成

前言

海岛老师写的真的好,感觉代码全篇没有一句废话,自己的代码能力还是太弱了,第一回交了只拿了30分,后来看了海岛老师的博客,更换了思路交了80分,最后完善后(自己的想法还是有漏洞),最终AC,强烈推荐看海岛老师的博客题解,在此发篇博客向海岛老师致敬,https://blog.csdn.net/tigerisland45/article/details/81697594

收获

感觉此次最大的收获竟然是——isdigit(cha c),C 库函数 bool isdigit(int c) 检查所传的字符是否是十进制数字字符。

Code

#include <bits/stdc++.h>
#define MAX 105
using namespace std;
string a[MAX], b[MAX];
int n, m;
bool match(string& p, string& t, bool flag)
{
	int ps = 0, ts = 0;
	while (ps < p.length() && ts < t.length()) {
		if (p[ps] == t[ts]) {
			ps++; ts++;
		} else {
			if (p[ps++] != '<') return false;
			else {
				if (flag) cout << " ";
				if (p[ps] == 'i') {
					bool ok = false;
					while (t[ts] != '/' && isdigit(t[ts])) {
						if (t[ts] != '0')
							ok = true;
						if (flag && ok)
								cout << t[ts];
						ts++;
					}
					if (!ok) 
						return false;
					ps += 4;
				} else if (p[ps] == 's') {
					bool ok = false;
					while (t[ts] && t[ts] != '/') {
						ok = true;
						if (flag)
							cout << t[ts];
						ts++;
					}
					if (!ok)
						return false;
					ps += 4;
				} else if (p[ps] == 'p') {
					if (flag)
						while (t[ts])
							cout << t[ts++];
					return true;
				}
			}
		}
	}
	return ps == p.length() && ts == t.length();
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for (int i = 0; i < m; i++) {
		string s;
		cin >> s;
		bool flag = false;
		for (int j = 0; j < n; j++) {
			if (match(a[j], s, false)) {
				flag = true;
				cout << b[j] << " ";
				match(a[j], s, true);
				break;
			}
		}
		if (!flag) cout << "404";
		cout << endl;
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

水能zai舟

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

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

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

打赏作者

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

抵扣说明:

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

余额充值