1. 程式人生 > >【離散數學一】 誰是作案嫌疑人?

【離散數學一】 誰是作案嫌疑人?

Problem Description

刑偵大隊對涉及六個嫌疑人的一樁疑案進行分析:
一、a ,b至少有一人作案;
二、a,e,f三人中至少有兩人蔘與作案;
三、 a ,d不可能是同案犯;
四、b,c或同時作案,或與本案無關;
五 c,d中有且只有一人作案;
六 如果d沒有參與作案則e也不可能參與作案。
試編寫程式,尋找作案人。

Input

多組測試資料,對於每組測試資料,第 1 行輸入 6 個空格分隔的整數,代表a、b、c 、d 、e 、f的編號,編號x範圍(1 <= x <= 6),且編號互不相同。

Output

對於每組測試資料,第 1 行至第 6 行分別輸出對 a、b、c 、d 、e 、f的判斷,詳細輸出格式請參考樣例。
 

Sample Input

1 2 3 4 5 6

Sample Output

The suspects numbered 1 are criminals.
The suspects numbered 2 are criminals.
The suspects numbered 3 are criminals.
The suspect numbered 4 is not a criminal.
The suspect numbered 5 is not a criminal.
The suspects numbered 6 are criminals.

Hint

gcc解法:#include <stdio.h>
int main()
{
   int a, b, c, d, e, f, a1, a2, a3, a4, a5, a6;
   while(scanf("%d %d %d %d %d %d",&a1, &a2, &a3, &a4, &a5, &a6)!=EOF)
   {
       int count = 0;
       for(a=0;a<=1;a++)
       {
           for(b = 0;b<=1;b++)
           {
               for(c = 0;c <= 1;c++)
               {
                   for(d = 0;d <= 1;d++)
                   {
                       for(e = 0;e <= 1;e++)
                       {
                           for(f = 0;f <= 1;f++)
                           {
                               if(a==1||b==1)count++;
                               if((a==1&&e==1)||(a==1&&f==1)||(e==1&&f==1))count++;
                               if(!(a==1&&d==1))count++;
                                if((b==1&&c==1)||(b==0&&c==0))count++;
                               if((c==0&&d==1)||(c==1&&d==0))count++;
                               if(d==1||(d==0&&e==0))count++;
                               if(count==6)
                               {
                                   printf("The suspects numbered %d are criminals.\n",a1);
                                   printf("The suspects numbered %d are criminals.\n",a2);
                                   printf("The suspects numbered %d are criminals.\n",a3);
                                   printf("The suspect numbered %d is not a criminal.\n",a4);
                                   printf("The suspect numbered %d is not a criminal.\n",a5);
                                   printf("The suspects numbered %d are criminals.\n",a6);
                               }
                           }
                       }
                   }
               }
           }
       }
   }
    return 0;

}

g++解法:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a,b,c,d,e,f;
    while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        printf("The suspects numbered %d are criminals.\n",a);
        printf("The suspects numbered %d are criminals.\n",b);
        printf("The suspects numbered %d are criminals.\n",c);
        printf("The suspect numbered %d is not a criminal.\n",d);
        printf("The suspect numbered %d is not a criminal.\n",e);
        printf("The suspects numbered %d are criminals.\n",f);
    }
    return 0;
}