question link
submission link
/*here I’ve used a set to store numbers from 1to 7and run a loop when i get all the numbers then i break the loop */
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
set t;
int num=0,k;
while(n–)
{
if(t.size()==7)Preformatted text
break;
cin>>k;
if(k>=1&&k<=7)
{
t.insert(k);
}
num++;
}
cout<<num<<endl;
t.clear();
}
return 0;
}
1 Like
Hey buddy your code is messed up , just put your code on ideone and run it and share the link . You can format your code by adding special chacter in the beginning and at end of your code . add ` special character 3 times in start and end . this special chacter is just above tab in standard keyboard and below of esc key .
You are getting wrong answer because you are not taking all the input , as soon as you found first 7 values you break out of loop and remaining elements of array is left , which is giving wrong answer . So take all the input and as soon as your set size becomes 7 store it into ans and print afterwards.
1 Like
but it passing the sample test case
check this test case :-
3
7
1 2 3 4 5 6 7
8
1 2 3 4 5 6 7 8
9
1 2 3 4 5 6 7 8 9
correct O/P:-
7
7
7
Your O/P:-
7
7
8
thank you very much for your help ,now i understand my mistake.
1 Like