Waterloo Cup to help Granny cross the street Java

Source: Internet
Author: User
Algorithm to improve the time limit: 1.0s memory limit: 256.0MB altogether has 5 red scarf, the number is a, B, C, D, E, the old woman was one of them helped across the road.

Five red scarves each speak:

A: Neither I nor E have helped the old lady.

B: Granny was helped by one of the C and E.

C: The granny was one of me and D who helped the street.

D:b and C didn't help Granny cross the street.

E: I didn't help Granny.


Known five red scarf and only 2 people are telling the truth, please ask who helped this granny over the street.

If there are multiple answers, the output is in one line and the number is separated by a space.


For example

A B C D E (This is obviously not the correct answer)

public class Main {
		static int a[]=new int[5];
		
	public static void Main (string[] args) {
		int sum; 
	    for (int i=0; i<5; i++)  
	    {  
	        sum=0;//records the number of truths  
	        
	        a[i]=1;//The assumption that the first person to help  , to help the note is 1, did not help 0
	        if (a[0]==0& &a[4]==0)//a said  , if a does not help and E did not help, is the truth
	            sum++;            Then sum++
	        if (a[2]!=0| | a[4]!=0)//b said  
	            sum++;  
	        if (a[2]!=0| | a[3]!=0)//c  
	            sum++;  
	        if (a[1]==0&&a[2]==0)//d  
	            sum++;  
	        if (a[4]==0)//e  
	            sum++;  
	        if (sum==2)//Exactly two people say the truth  
	        	{System.out.print ((char) (' A ' +i) + ");}
	        a[i]=0;//at the end of each loop 0}}}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.