Can anyone please help me in understanding how to take input in problems like these which do not specify the number of test cases?
int n;
while(cin>>n)
{
//your logic
}
2 Likes
You can simply use:
while(scanf("%d", &n) == 1)
{
//Do Something
}
1 Like
You can use a custom input method and check for EOF that is End Of File.
int input()
{
char c;
int flag=0;
c=getchar();
if(c==EOF)
return -1;
while(c!='\0')//stop input when null character is encountered meaning a number has ended
{
//dow what you want
//save the data or operate on data
c=getchar();
}
//here return the data acquired
return 0;
}
This will take input character by character . It is upto you how to use those characters . You can transform it into a number or store it as a string and much much more . In the loop in main you can check for if the input () function return -1 to stop executing the program.