#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int freq;
while (cin >> freq)
{
int* input = new int;
for (int i = 0; i < freq; ++i)
cin >> input[i];
sort(input, input + freq);
bool flag = true;
for (int i = 0; i < freq-1; i++)
{
flag = input[i]+1 != input[i+1] ? false : true;
if (flag==false) break;
}
if (flag == true)
cout <<input[0]<<' '<<input[freq-1]<< " yes" << endl;
else
cout <<input[0]<<' '<<input[freq-1]<< " no" << endl;
}
}
您的答案為: 1 8241 no 正確答案為: 1 10 no
您的答案為: 99 0 yes 正確答案為: 99 106 yes
#include
#include
using namespace std;int main()
{int freq;
while (cin >> freq)
{
int* input = new int;
for (int i = 0; i < freq; ++i)
cin >> input[i];sort(input, input + freq);
bool flag = true;
for (int i = 0; i < freq-1; i++)
{
flag = input[i]+1 != input[i+1] ? false : true;
if (flag==false) break;
}if (flag == true)
cout <<input[0]<<' '<<input[freq-1]<< " yes" << endl;
else
cout <<input[0]<<' '<<input[freq-1]<< " no" << endl;}
}
#26: 4% WA (line:1)
您的答案為: 1 8241 no 正確答案為: 1 10 no#27: 4% WA (line:1)
您的答案為: 99 0 yes 正確答案為: 99 106 yes
這一行改成:
int* input = new int[freq];
就AC