121 - Pipe Fitters

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

foolishzhu
New poster
Posts: 4
Joined: Sun Jul 02, 2006 5:00 am

How to know the end of input parameters?

Post by foolishzhu »

Many problems in Volums have such input as follows:
(problem 121 : Pipe Fitters )

Sample Input

3 3
2.9 10
2.9 10.5
11 11

The input has no end flag to tell you where is the end. If it is a file, feof() can be called to judge. However ,it seems to me no way to write a program in C++ to judge there is end if it get on screen. WOuld someone tell me how to do this?
Many thanks

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes »

just use :

Code: Select all

while (scanf("%lf %lf",&a,&b)  != EOF) {
//process
}
Hope it helps... :wink:

jtmh
New poster
Posts: 16
Joined: Sat Jul 15, 2006 8:34 pm
Location: Taiwan

Post by jtmh »

Or use:

Code: Select all

while (cin >> a >> b)
{
	// process
}

brahle
New poster
Posts: 4
Joined: Mon May 22, 2006 11:39 am

Post by brahle »

or something like this:

Code: Select all

while( scanf( "%lf%lf", &a, &b ) == 2 ) ) {
//process
}

mukeshtiwari
Learning poster
Posts: 63
Joined: Tue Mar 07, 2006 6:51 pm
Location: india

Post by mukeshtiwari »

hi this link could be useful for solving this problems...
http://www.stetson.edu/~efriedma/cirinsqu/

hasib_bd
New poster
Posts: 14
Joined: Wed Apr 30, 2008 12:39 pm

Re: #121 - Pipe Fitters

Post by hasib_bd »

My AC program generates below outputs for the following intputs:

INPUT:

Code: Select all

0.2 128
0.4 128
0.6 128
0.8 128
1 128
1.2 128
1.4 128
1.6 128
1.8 128
2 128
2.2 128
2.4 128
2.6 128
2.8 128
3 128
3.2 128
3.4 128
3.6 128
3.8 128
4 128
4.2 128
4.4 128
4.6 128
4.8 128
5 128
5.2 128
5.4 128
5.6 128
5.8 128
6 128
6.2 128
6.4 128
6.6 128
6.8 128
7 128
7.2 128
7.4 128
7.6 128
7.8 128
8 128
8.2 128
8.4 128
8.6 128
8.8 128
9 128
9.2 128
9.4 128
9.6 128
9.8 128
10 128
OUTPUT:

Code: Select all

0 grid
0 grid
0 grid
0 grid
128 grid
128 grid
128 grid
147 skew
147 skew
256 grid
256 grid
256 grid
294 skew
383 skew
384 grid
384 grid
384 grid
510 skew
510 skew
515 skew
515 skew
515 skew
638 skew
638 skew
662 skew
662 skew
765 skew
765 skew
765 skew
809 skew
893 skew
893 skew
893 skew
893 skew
956 skew
1020 skew
1020 skew
1029 skew
1029 skew
1148 skew
1148 skew
1148 skew
1176 skew
1275 skew
1275 skew
1275 skew
1275 skew
1323 skew
1403 skew
1403 skew
Hope it might help

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

Re: #121 - Pipe Fitters

Post by serur »

By the way what's the output for this:

Code: Select all

2.43 2.43
This input was inspired by the fact sqrt(2) = 1.41, so the answer should be

Code: Select all

5 skew
.
However, most of the AC code returns

Code: Select all

4 grid

Post Reply

Return to “Volume 1 (100-199)”