Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
code...../* @poj 3753 原来不需要写一个函数 */ #include<iostream> #include<string> using namespace std; int solve(string s, string d) { //返回匹配长度 int ans = 0; if (d == "NULL") return 0; if (d.length() == 1) { if (s.find(d[0]) != string::npos){ for (int i = 0; i < s.length(); i++) { if (d[0] == s[i]){ return i; } } } } for (int i = 0; i < s.length(); i++) { int l = 1; if (s[i] == d[0]) { int k = i + 1; for (int j = 1; j < d.length(); j++) { if (s[k++] != d[j]){ break; } else{ l++; } } } if (l == d.length()) { return i; } } return s.length(); } int main() { string sstr, dstr; while (cin >> sstr) { while (cin >> dstr) { if (dstr == "END") break; int ans = solve(sstr, dstr); cout << ans << " "; if (ans == 0){ cout << "NULL"; } else{ for (int i = 0; i < ans; i++) cout << sstr[i]; } cout << endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator