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

1A代码,爽!

Posted by 834208094 at 2012-09-02 10:19:50 on Problem 1250
#include<iostream>
#include <string>
#include<queue>
#include<stdio.h>
#include<string.h>
using namespace std;
int nums, k, top;
string customers;
char map[25], used[25];
int howmanycustomers()
{
	int cnt = 0;
	for(int i=0; i<nums; i++) if(map[i] != '~') cnt++;
	return cnt;
}
void del(char a)
{
	for(int i=0; i<nums; i++) if(map[i] == a) map[i] = '~';
}
void ins(char a)
{
	for(int i=0; i<nums; i++)
	{
		if(map[i] == '~')	
		{
			map[i]	= a;
			return;
		}
	}
}
int con(char a)
{
	for(int i=0; i<nums; i++)
	{
		if(map[i] == a) return 1;
	}
	return 0;	
}
int con2(char a)
{
	for(int i=0; i<top; i++) if(used[i] == a) return 1;
	return 0;
}
int main()
{
//	freopen("D:\\in.txt","r",stdin);
//	freopen("D:\\out.txt","w",stdout);
	while(scanf("%d", &nums) != EOF && nums != 0)
	{
		cin>>customers;
		for(int i=0; i<nums; i++) map[i] = '~';
		int ans = 0;
		top = 0;
		for(int i=0; i<customers.length(); i++)
		{
			k = howmanycustomers();
			if(k <= nums && con(customers[i])) del(customers[i]);
			else if(k < nums && !con(customers[i])) ins(customers[i]);
			else if(k == nums && !con(customers[i]) && !con2(customers[i]))
			{
				ans++;
				used[top++] = customers[i];	
			} 
		}
	//	cout<<ans<<endl;
		if(!ans)cout<<"All customers tanned successfully."<<endl;
		else cout<<ans<<" customer(s) walked away."<<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