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 AP0606409 at 2008-09-02 23:58:19 on Problem 2328
In Reply To:这样的算法是不是有很大问题?请大侠指正!不胜感激! Posted by:AP0606409 at 2008-09-02 16:58:09
> #include <iostream>
> using namespace std;
> int main()
> {
> 	int var;
> 	char dicats[9];
> 	int high_var=10,low_var=0;
> 	while ( cin >> var)
> 	{
> 		while (cin>>dicats)
> 		{
> 			if("too high"== dicats) 
> 			{
> 				high_var=var;
> 				continue;
> 			}
> 			else{
> 				if("too low"==dicats)
> 				{
> 					low_var=var;
> 					continue;
> 				}
> 				else{
> 					if( "right on"==dicats)
> 					{
> 						if(high_var<=low_var) cout<<"Stan is dishonest\n";
> 						else cout<<"Stan may be honest\n";
> 						break;
> 
> 					}
> 				}	
> 			}
> 		}
> 	}
> 	return 0;
> }
> 




















经修正后,编译正确  但还是wa

#include <iostream>
using namespace std;
#include<string>
int main()
{
	int var;

	string s,s1;
//	char dicats[9];
	int high_var=10;
	int	low_var=0;

	while ( cin >> var && var)
	{
		if(var<0 || var >10) 
		{
			throw "array not allow!";
			break;
		}

		cin>>s1>>s;

		if("high"== s) 
			
			if(high_var>var)
				high_var=var;
				//continue;
			
		if("low"==s)
		
			if(low_var<var)
				low_var=var;
				//continue;
		
		
		
		if("on"==s)
			if(high_var<=var || low_var>=var || high_var<low_var)
		{
			cout<<"Stan is dishonest\n";
			high_var=10;low_var=0;
		}
			else 
			{
				cout<<"Stan may be honest\n";
					high_var=10;low_var=0;
			}
						//break;

					
				
				//cout<<high_var;
				//break;
	//		}
	
	}
	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