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

stl太好用啦 哈哈 谢谢 306457592同学

Posted by lijinwu at 2010-01-13 11:32:56 on Problem 1270
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
char s[25],c[105];
string t;
int len;

bool valid()
{
	int tlen=strlen(c)/2;
	for(int i=0;i<tlen;++i)
		if(find(s,s+len,c[i*2])>find(s,s+len,c[i*2+1]))  // 用find
			return false;
	return true;
}

int main()
{
	int j;
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	while(getline(cin,t))  // 用getline 对string 操作
	{
		len=t.size();
		j=0;
		for(int i=0;i<len;i++)
		{
			if(t[i]<='z'&&t[i]>='a')
			{
				s[j]=t[i];
				j++;
			}
		}
		s[j]='\0';
		getline(cin,t);
		len=t.size();
		j=0;
		for(int i=0;i<len;i++)
		{
			if(t[i]<='z'&&t[i]>='a')
			{
				c[j]=t[i];
				j++;
			}
		}
		c[j]='\0';
		len=strlen(s);
		sort(s,s+len);
		if(valid())
			printf("%s\n",s);
		while(next_permutation(s,s+len))  // next_permutation
		{
			if(valid())
			{
				printf("%s\n",s);
			}
		}
		printf("\n");
	}
	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