as i remember the problem says that the sequence contain all the succesive difference 1 to n-1...
if n=1..then it should contain alll the differnece 1 to 0(1-1)..is'nt it!!!
so if n=1,the it will be jolly if the input is as follows..
int main()
{
vector<int> nums;
list<int> res;
int seq, num,result;
int num1,num2;
cin >> seq;
if(seq <= 0 || seq > 3000)
exit(0);
nums.reserve(seq);
//To store the input in nums
for(int i = 0 ;i < seq;i++)
{
cin >> num;
nums.push_back(num);
}
//to get the difference and store it in (res) vectore variable
vector<int>::iterator iter;
for(iter = nums.begin();iter != nums.end();iter++)
{
num1 = *iter;
iter++;
if(iter == nums.end())
break;
num2 = *iter;
iter--;
result = num1 - num2;
res.push_back(abs(result));//store the absolute value of result
}
One mistake I see is that the "j" in your "jolly" is lowercase but should be uppercase.
Learn to always test your solution against the example I/O before submitting
Edit: Also, change the exit(1) to exit(0), your program is supposed to terminate normally under all conditions.
[quote="chunyi81"]My AC program has a slightly different output than the one above.
My AC program outputs:
[code]
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Not jolly
Jolly
[/code]
As for which one is correct, it all comes down to the following input:
[code]
1 2
[/code]
Since there is only one integer, shouldn't the correct output be "Jolly"?[/quote][quote]
why the third case " 10 1 2 3 4 5 6 7 8 9 10" Not jolly ?[/quote]