題目連結: https://zerojudge.tw/ShowProblem?problemid=d123
# 解題思路
用兩層迴圈將所有狀況的記錄下來,如果已經有重複過了,就不是 B2-Sequence
# 程式碼
#include <iostream> | |
using namespace std; | |
int main() { | |
int b[100],n,count=1; | |
while(cin >> n){ | |
for(int i=0;i<n;i++) | |
cin >> b[i]; | |
int a[20001]={0},flag=1; | |
for(int i=0;i<n;i++){ | |
for(int j= i ;j<n;j++){ | |
if (a[b[i]+b[j]] == 1){ | |
flag=0; | |
break; | |
} | |
if (a[b[i]+b[j]] == 0) | |
a[b[i]+b[j]]++; | |
} | |
if (flag==0) | |
break; | |
} | |
if (flag == 1) { | |
cout << "Case #" << count <<": It is a B2-Sequence." << endl << endl; | |
} | |
if (flag == 0) { | |
cout << "Case #" << count <<": It is not a B2-Sequence." << endl << endl; | |
} | |
count++; | |
} | |
} |