Determine ranking in the game five diving athlete / OK murderer / print Pascal's Triangle

1.5 athletes took part in the 10-meter platform diving competition, someone let them predict match results,
player A says: B second, my third;
B players said: I second, E IV;
C players, said: I am the first, D second;
D players, said: C Finally, my third;
E contestant said: I IV, a first;
after the game, each player say half right, please programmed to determine the ranking of the game.

(1) by the circulation of each person may determine the ranking
(2) can not be repeated because the ranking A B C D E = 120
(. 3) of each said half for personal
((b == 2) + ( a == 3) == 1)

#include<stdlib.h>
#include<stdio.h>
int main()
{
	int a, b, c, d, e;
	for (a = 1; a <= 5; a++)
	{
		for (b = 1; b <= 5; b++)
		{
			for (c = 1; c <= 5; c++)
			{
				for (d = 1; d <= 5; d++)
				{
					for (e = 1; e <= 5; e++)
					{
						if (a*b*c*d*e==120)
						{					
							if (((b == 2) + (a == 3) == 1) && ((b == 2) 
							+ (e == 4) == 1) && ((c == 1) + (d == 2) == 1) &&
							+  ((c == 5) + (d == 3) == 1) && ((e == 4) + (a == 1) == 1))
							{
								printf("a=%d b=%d c=%d d=%d e=%d\n", a, b, c, d, e);
							}
						}
					}
				}
			}
		}
	}
	system("pause");
	return 0;
}

2. Japan somewhere there have been a murder, the police through the investigation to determine the murderer will be for four.
Of a suspect. The following is the four suspects confession.
A said: not me.
B said: It is C.
C said: It is D.
D said: C nonsense
known three people told the truth, one person was lying.
Based on this information now, please, write a program to determine in the end who is the murderer.

#include<stdio.h>
#include<stdlib.h>
void Murderer()
{
	for (char i = 'A'; i < +'D'; i++)
	{
		if ((i != 'A') + (i == 'C') + (i == 'D') + (i != 'D') == 3)
		{
			printf("凶手是%c\n", i);
		}
	}
}
int main()
{
	Murderer();
	system("pause");
	return 0;
}

3. Pascal's Triangle print on the screen.
/ *
. 1
. 1. 1
. 1 2. 1
. 1. 3. 3. 1
. 1. 4. 4. 6. 1
* /

#include<stdlib.h>
#include<stdio.h>
#define SIZE 5
int main()
{
	int arr[SIZE][SIZE] = { 0 };
	//确定杨辉三角的边沿数为一
	for (int i = 0; i <= SIZE; i++)
	{
		arr[i][0] = 1;
		arr[i][i] = 1;
	}
	//利用for循环求得一行中 中间的数字
	for (int i = 2; i < SIZE; i++)
	{
		for ( int j = 1; j < i; j++)
		{
			arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
		}
	}
	//打印杨辉三角
	for (int i = 0; i < SIZE; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}
	system("pause");
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44936160/article/details/90489396