First, the sequence must start with the number greater than 0.
Second,
if(i>=2)if(Arr==(Arr[i-1]+Arr[i-2]))flg=1;
this line is wrong.
Consider the test case:
3
1 3 4
The sequence is a B2 sequence but your output shows it is not a B2 sequence.
Moderator: Board moderators
if(i>=2)if(Arr==(Arr[i-1]+Arr[i-2]))flg=1;
Code: Select all
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int cases, i, number[102], caseno = 0;
while(scanf("%d", &cases) == 1)
{
int count = 0;
for(i = 1; i <= cases; i++)
{
scanf("%d", &number[i]);
}
for(i = 1; i <= cases; i++)
{
if(number[i+1] - number[i] == number[i])
{
count = 1;
}
}
if(count == 1)
{
printf("Case #%d: It is a B2-Sequence.\n", ++caseno);
}
else
{
printf("Case #%d: It is not a B2-Sequence.\n", ++caseno);
}
if(caseno > 0)
{
printf("\n");
}
}
return 0;
}
Code: Select all
4
1 2 3 3
4
15 16 17 18
4
-5 0 5 9
6
1 9 19 0 45 70
6
1 9 19 45 70 150
5
15 16 -1 17 18
4
2 2 2 3
4
2 2 2 2
4
1 9 18 36
5
1 9 10 18 36
Code: Select all
Case #1: It is not a B2-Sequence.
Case #2: It is not a B2-Sequence.
Case #3: It is not a B2-Sequence.
Case #4: It is not a B2-Sequence.
Case #5: It is a B2-Sequence.
Case #6: It is not a B2-Sequence.
Case #7: It is not a B2-Sequence.
Case #8: It is not a B2-Sequence.
Case #9: It is a B2-Sequence.
Case #10: It is not a B2-Sequence.
Code: Select all
#include <iostream>
using namespace std;
int main ()
{
int t=1,num[99],sum[10000],s,c;
bool res;
while (cin>>s)
{
res=true;
for (int j=0;j<s;j++)
cin>>num[j];
for (int k=0;k<s-1;k++)
if (num[k]<1 || num[k]>=num[k+1] )
{
res=false;
break;
}
c=0;
for (int i=0;i<s;i++)
for (int l=i;l<s;l++)
{
sum[c]= num[i]+num[l];
c++;
}
for (int x=0;x<s;x++)
for (int y=0;y<s;y++)
if (sum[x]==sum[y] && y!=x) res=false;
else continue;
if (res==true)
cout<<"Case #"<<t<<": It is a B2-Sequence."<<endl;
else if (res==false)
cout<<"Case #"<<t<<": It is not a B2-Sequence."<<endl;
cout<<endl;
t++;
}
return 0;
}
Code: Select all
#include <iostream>
using namespace std;
int main ()
{
int t=1,num[99],sum[10000],s,c;
bool res;
while (cin>>s)
{
res=true;
for (int j=0;j<s;j++)
cin>>num[j];
for (int k=0;k<s-1;k++)
if (num[k]<1 || num[k]>=num[k+1] )
{
res=false;
break;
}
c=0;
for (int i=0;i<s;i++)
for (int l=i;l<s;l++)
{
sum[c]= num[i]+num[l];
c++;
}
for (int x=0;x<s;x++)
for (int y=0;y<s;y++)
if (sum[x]==sum[y] && y!=x) res=false;
else continue;
if (res==true)
cout<<"Case #"<<t<<": It is a B2-Sequence."<<endl;
else if (res==false)
cout<<"Case #"<<t<<": It is not a B2-Sequence."<<endl;
cout<<endl;
t++;
}
return 0;
}
Code: Select all
3
1 3 5
Code: Select all
Yeah...This is a AC code. I just don't know why the system told that this is wrong answer before...
Code: Select all
#include<stdio.h>
int main()
{
int i,j,k,x,y,z,n,tc=0,ara[101],f;
long sum[100000];
while(scanf("%d",&n)==1){
tc++;
for(i=0; i<n; i++){
scanf("%d", &ara[i]);
}
f=0;
for(i=1; i<n; i++){
if(ara[i]<=ara[i-1] || ara[i-1]<1){
f=1;
break;
}
}
if(f==1){
printf("Case #%d: It is not a B2-Sequence.\n",tc);
continue;
}
k=0;
for(i=0; i<n; i++){
for(j=n-1;j>=i;j--){
sum[k] = ara[i]+ara[j];
k++;
}
}
z=0;
for(x=0; x<k; x++){
for(y=k-1; y>x; y--){
if(sum[x]==sum[y]){
z=1;
break;
}
}
if(z==1) break;
}
if(z==0) printf("Case #%d: It is a B2-Sequence.\n",tc);
else printf("Case #%d: It is not a B2-Sequence.\n",tc);
printf("\n");
}
return 0;
}