201803-3URL映射(50)
Posted sanshi-2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了201803-3URL映射(50)相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h> using namespace std; const int maxn = 100 + 3; const int maxm = 100 + 3; int n, m; struct Node{ string s; string name; vector<Node*>next; }; Node root; void dfs(Node* u) { if(u->name != "") cout << u->name; cout << u->s << ‘ ‘; for(int i = 0; i < u->next.size(); i++) dfs(u->next[i]); } void addNode(string s1, string s2) { vector<string>ss1; int last = 0; for(int i = 1; i < s1.size(); i++){ if(s1[i] == ‘/‘){ ss1.push_back(s1.substr(last + 1, i - last - 1)); last = i; }else if(i == s1.size() - 1){ ss1.push_back(s1.substr(last + 1, i - last)); } } // for(string s : ss1) // cout << s << endl; Node* u = &root; for(int i = 0; i < ss1.size(); i++){ bool ok = 0; for(int j = 0; j < u->next.size(); j++){ if(u->next[j]->s == ss1[i]){ u = u->next[j]; ok = 1; break; } } if(!ok){ Node* p = new Node(); p->s = ss1[i]; if(i == ss1.size() - 1) p->name = s2; u->next.push_back(p); u = p; } } //dfs(&root); } bool match(string pattern, string& text) //同时去掉前导0 { if(pattern == "<path>") return true; if(pattern[0] != ‘<‘) return pattern == text; bool isnum = true; for(int i = 0; i < text.size(); i++){ if(!isdigit(text[i])){ isnum = false; break; } } if(isnum){ //cout << "fffffffffffffffffffff" << text << endl; int i = 0; while(text[i] == ‘0‘) i++; text.erase(0, i); //cout << "fffffffffffffffffffff" << text << endl; return pattern == "<int>"; } return pattern == "<str>"; } void solve(string s1) { vector<string>ss1; int last = 0; for(int i = 1; i < s1.size(); i++){ if(s1[i] == ‘/‘){ ss1.push_back(s1.substr(last + 1, i - last - 1)); last = i; }else if(i == s1.size() - 1){ ss1.push_back(s1.substr(last + 1, i - last)); } } vector<string>args; string name; Node* u = &root; int OK = true; int path = 0; for(int i = 0; i < ss1.size(); i++){ string& s = ss1[i]; int ok = 0; for(int j = 0; j < u->next.size(); j++){ if(match(u->next[j]->s, s)){ if(u->next[j]->s == "<path>"){ for(int k = i; k < ss1.size(); k++){ if(args.size() == 0) args.push_back(""); args[args.size() - 1] += (k == i ? "" : "/") + ss1[k]; } name = u->next[j]->name; path = 1; break; } if(i == ss1.size() - 1){ if(u->next[j]->name != ""){ name = u->next[j]->name; ok = 1; } } else ok = 1; if(u->next[j]->s[0] == ‘<‘) args.push_back(s); u = u->next[j]; break; } } if(path) break; if(!ok){ OK = false; } } if(!OK) cout << "404" << endl; else{ cout << name; for(int i = 0; i < args.size(); i++) cout << ‘ ‘ << args[i]; cout << endl; } } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); while(cin >> n >> m && n){ root.s = "/"; for(int i = 0; i < n; i++){ string s1, s2; cin >> s1 >> s2; addNode(s1, s2); } for(int i = 0; i < m; i++){ string s; cin >> s; solve(s); } //dfs(&root); } return 0; }
以上是关于201803-3URL映射(50)的主要内容,如果未能解决你的问题,请参考以下文章
具有运行时 pojos 的带有 Hibernate 的 OSGi 片段包