# Java Algorithm Blue Bridge Cup fu Granny Street

Source: Internet
Author: User

A total of 5 red scarves, numbered A, B, C, D, E, the grandmother was one of them to help cross the road.

Five red scarves speak each other:

A: Neither I nor e have helped granny

B: Granny is a C and E, one of them helped me through the street.

C: Granny's been helped by me and D.

D:b and C are not helping granny across the street.

E: I didn't help grandma.

It is known that there are five red scarves and only 2 people are telling the truth, who helped the old lady through the street?

If there are multiple answers, output in one line, separated by a space between the numbers.

For example
A B C D E (which is obviously not the correct answer)

Code::

Package Blue Bridge cup Java algorithm training;

public class _1 help granny cross the road {
public static void Main (string[] args) {
I refers to each person, sum records the number of telling the truth
for (int i = 1; I <= 5; i++) {
int sum = 0;
if (i! = 1 && I! = 5) sum++;//a said if correct, sum+1
if (i = = 3 | | i = = 5) sum++;//b said if correct, sum+1
if (i = = 3 | | i = = 4) sum++;//c said if correct, sum+1
if (i! = 2 && I! = 3) sum++;//d said if correct, sum+1
if (i! = 5) sum++;//e said if the word is correct, sum+1
if (sum = = 2) {
System.out.print ((char) (i-1+ ' A ') + "");
}

}

}

}

Java Algorithm Blue Bridge Cup fu Granny Street

Related Keywords:

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.