Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

code.....

Posted by xpandening at 2015-08-02 13:33:57 on Problem 3753
/*
 @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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator