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

Re:炫耀一下自己:一次AC

Posted by huangzhifei at 2009-09-24 10:56:11 on Problem 1270
In Reply To:炫耀一下自己:一次AC Posted by:306457592 at 2009-08-28 21:27:47
> 是用暴搜来做的。
> #include <iostream>
> #include <string>
> #include <algorithm>
> using namespace std;
> 
> string t;
> char s[24], a[104];
> 
> int cmp(const void* p, const void* q) {
> 	return *(char*)p - *(char*)q;
> }
> 
> bool isvalid() {
> 	char p, q;
> 	int i, j;
> 	int n = strlen(s);
> 	int m = strlen(a) / 2;
> 
> 	for (j=0; j < m; j++) {
> 		p = a[j*2];
> 		q = a[j*2+1];
> 		for (i=0; i < n; i++) {
> 			if (s[i] == p)
> 				break;
> 			if (s[i] == q)
> 				return false;
> 		}
> 	}
> 	return true;
> }
> 
> int main()
> {
> 	int i, j, n;
> 
> 	while (getline(cin, t)) {
> 		n = t.size();
> 		for (i=j=0; i < n; i++) {
> 			if (t[i]>='a' && t[i]<='z') {
> 				s[j] = t[i];
> 				j++;
> 			}
> 		}
> 		s[j] = '\0';
> 
> 		getline(cin, t);
> 		n = t.size();
> 		for (i=j=0; i < n; i++) {
> 			if (t[i]>='a' && t[i]<='z') {
> 				a[j] = t[i];
> 				j++;
> 			}
> 		}
> 		a[j] = '\0';
> 
> 		n = strlen(s);
> 		qsort(s, n, sizeof(char), cmp);
> 		if (isvalid())
> 			printf("%s\n", s);
> 		while(next_permutation(s, s+n))
> 			if (isvalid())
> 				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