You are not logged in. Please login at www.codechef.com to post your questions!

×

How should I take input in problems like these?

Can anyone please help me in understanding how to take input in problems like these which do not specify the number of test cases?

asked 20 Jul '17, 18:44

dhruvsomani's gravatar image

4★dhruvsomani
1448
accept rate: 8%


int n;

while(cin>>n)

{

//your logic

}

link

answered 20 Jul '17, 19:02

hruday968's gravatar image

4★hruday968
1.7k210
accept rate: 14%

You can simply use:

while(scanf("%d", &n) == 1)

{

//Do Something

}

link

answered 20 Jul '17, 19:04

abdullah768's gravatar image

6★abdullah768
2.5k421
accept rate: 17%

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.

link

answered 20 Jul '17, 19:08

trashmaster's gravatar image

2★trashmaster
98619
accept rate: 12%

edited 20 Jul '17, 19:08

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,738
×170
×7

question asked: 20 Jul '17, 18:44

question was seen: 526 times

last updated: 20 Jul '17, 19:08