#include<iostream>
#include<vector>
using namespace std;
int main() {
int n,m=1;
while (cin >> n)
{
bool flag = 0;
int data[111];
int sum[20001] = { 0 }, count = 0;
for (int i = 0; i < n; i++)
{
cin>>data[i];
if (i >= 1&& data[i] <= data[i - 1])
flag = 1;
}
if (data[0] < 1)
flag = 1;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
sum[data[i] + data[j]]++;
for (int i = 0; i < 20001; i++)
if (sum[i] == 2)
{
flag = 1;
break;
}
if (!flag)
cout << "Case #" << m << ": It is a B2-Sequence." << endl;
else
cout << "Case #" << m << ": It is not a B2-Sequence." << endl;
m++;
}
}
附上程式碼
WA15 請問是哪裡的問題呢
更正 是sum[i]>=2
更正 是sum[i]>=2
for (int j = i + 1; j < n; j++)
改一個字