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:大家注意了!有陷阱

Posted by blueDesert at 2010-12-08 21:01:50 on Problem 2328
In Reply To:大家注意了!有陷阱 Posted by:tfaylsh at 2007-12-22 12:52:54
> 1.初始化的时候min=0;max=11;
> 2.if(s2=="high" && to>n)
>   if(s2=="low" && from<n)
>   必须把条件都标好啊,如果直接else会有问题,
>   测试数据中可能有垃圾的非"too high""too low""right on"的信息;
> 3.不要用getline;可能有错!
不管初始化为1/10, 0/11都是能过的, 就是判修改min/max规则稍有不同啦。。。
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <climits>
//#include "Derive.h"
//POJ:2845
using namespace std;
#define EPS 1E-6
#define LEN 50010
#define QUEUELEN 2000
#define P 3.1415927

int main()
{
	char response[3][10] = {
		"high", 
		"low", 
		"on"
	};
	int number;
	char t[10], str[10];
	int low, high;
	bool start = true, end = false;
	bool flag = true;
	while(scanf("%d", &number))
	{
		if(number == 0) break;
		scanf("%s%s", t, str);
		if(start)
		{
			start = false;
			end = false;
			flag = true;
			low = 1;
			high = 10;
		}
		if(!strcmp(response[0], str))
		{
			if(number - 1 < high)
				high = number - 1;
			if(low > high)
				flag = false;
		}
		if(!strcmp(response[1], str))
		{
			if(number + 1 > low)
				low = number + 1;
			if(low > high)
				flag = false;
		}
		if(!strcmp(response[2], str))
		{
			end = true;
			if(number < low || number > high || low > high)
				flag = false;
		}

		if(end)
		{
			start = true;
			if(flag)
				printf("Stan may be honest\n");
			else printf("Stan is dishonest\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