URL映射

//80分.....不知道哪有问题了.......

#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>

using namespace std;

const int N = 100+5;

struct Node{
	string pre;
	string nxt; 
}q[N]; 

bool Match(Node t, string s){
	string s1 = t.pre;
	vector<string> v;
	
	for(int i=0, j=0; s[j] || s1[i]; ){
		if(s1[i] == '\0' || s[j] == '\0')//加了该行 80....然后剩下运行错误.... 
			return false;
			
		if(s1[i] == s[j]){
			i++;
			j++;
		} else if(s1[i] != '<'){
			return false;
		} else if(s1[i+1]=='i'){
			int tmp = 0;
			
			while(isdigit(s[j])){
				tmp *= 10;
				tmp += s[j]-'0';
				j++;
			}
			if(s[j] != '/'){
				return false;
			}
			i += 5;	
			
			//cout << "digit" <<  tmp << endl;
			char *st;
			sprintf(st, "%d", tmp);
			v.push_back(st);
		}else if(s1[i+1]=='s'){
			string tmp="";
			while(isalpha(s[j]) && s[j]!='/'){
				tmp += s[j];
				j++;
			}
			i += 5;
			
			//cout << "str" <<  tmp << endl;

			v.push_back(tmp);
		}else if(s1[i+1] == 'p'){
			string tmp=s.substr(j);
			v.push_back(tmp);

			i += 6;
			
			//cout << "path" <<  tmp << endl;
			j = s.length();
		}
	}
	
	cout << t.nxt << " ";
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
	
	return true;
}

int main()
{
	int n, m;
	
	cin >> n >> m;
	cin.get();	
	string s;
	for(int i=0; i<n; i++){
		getline(cin, s);
		
		stringstream ss(s);
		ss >> s;
		q[i].pre = s;
		ss >> s;
		q[i].nxt = s;
	}
	
	string s1, s2; 
	
	for(int i=0; i<m; i++){
		getline(cin, s);
		
		bool flag = false;
		
		for(int j=0; j<n; j++){
		//	cout << "match " << q[j].pre << ":" << s << endl;
			if(Match(q[j], s)){
				flag = true;
				break;
			}
		}
		if(!flag){
			cout << "404" << endl;
		}	
	}	
	return 0;
}

 

//只有70分 暂时想不到哪里没想到 

#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>

using namespace std;

const int N = 200+5;

struct Node{
	string pre;
	string nxt; 
}q[N]; 

bool Match(Node t, string s){
	string s1 = t.pre;
	int cnt = 0;
	vector<string> v;
	
	for(int i=0, j=0; s[j] || s1[i]; ){
		if(s1[i] == s[j]){
			cnt++;
			i++;
			j++;
		} else if(s1[i] != '<'){
			return false;
		} else if(s1[++i]=='i'){
			int tmp = 0;
			
			while(isdigit(s[j])){
				tmp *= 10;
				tmp += s[j]-'0';
				j++;
			}
			if(s[j] != '/'){
				return false;
			}
			i += 4;	
			
			//cout << "digit" <<  tmp << endl;
			char *st;
			sprintf(st, "%d", tmp);
			v.push_back(st);
		}else if(s1[i]=='s'){
			string tmp="";
			while(isalpha(s[j]) && s[j]!='/'){
				tmp += s[j];
				j++;
			}
			i += 4;
			
			//cout << "str" <<  tmp << endl;

			v.push_back(tmp);
		}else if(s1[i] == 'p'){
			string tmp=s.substr(j);
			v.push_back(tmp);

			i += 5;
			
			//cout << "path" <<  tmp << endl;
			j = s.length();
		}
	}
	
	cout << t.nxt << " ";
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
	
	return true;
}

int main()
{
	int n, m;
	
	cin >> n >> m;
	cin.get();	
	string s;
	for(int i=0; i<n; i++){
		getline(cin, s);
		
		stringstream ss(s);
		ss >> s;
		q[i].pre = s;
		ss >> s;
		q[i].nxt = s;
	}
	
	string s1, s2; 
	
	for(int i=0; i<m; i++){
		getline(cin, s);
		
		bool flag = false;
		
		for(int j=0; j<n; j++){
		//	cout << "match " << q[j].pre << ":" << s << endl;
			if(Match(q[j], s)){
				flag = true;
				break;
			}
		}
		if(!flag){
			cout << "404" << endl;
		}	
	}	
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值