need your help (two urgent tasks)

G

Gregory Edigaroff

Hello, Everybody!

Ok, I urgently need the solution for a following task in C++. This is the task from programmers contest,
so I believe somebody have a solution for it.
I need either a full source code or a simple description of algorithm to solve this task.

thank a lot in advance.

Unit Conversion
A (measurement) unit is here represented by a single word containing only lower-case letters. All
units are written as singular both in input and in output. A conversion fact relates the size of two
units.
You are to convert a quantity in one unit to the equivalent quantity in a different unit using only
a given set of conversion facts. These conversion facts are self consistent; there is never more
than one conversion chain from any unit to any other unit.

Input
The input will start with a number of lines, each containing a conversion fact in the form:
<v1> <u1> = <v2> <u2>
The elements <v1> and <v2> are positive real numbers (a sequence of decimal digits, containing
at most one decimal point), and <u1> and <u2> are strings containing only lower case letters
representing the name of a unit. The elements are separated by single spaces. The conversion fact
asserts that the quantity <v1><u1> is equal to the quantity <v2><u2>.
There will then a number of lines each representing a conversion request in the form:
<v3> <u1> = ? <u2>
The elements <u1> and <u2> are again unit names, which may or may not have occurred in the
conversion facts. All elements on the line are separated by single spaces (the equality sign and
question mark are surrounded by single spaces too). The end of data is represented by end-offile.

Output
For each conversion request there should be either the line
No conversion is possible.
if insufficient conversion facts have been given, or a line of the form
<v3> <u1> = <v4> <u2>
all elements are as in the conversion request, except that the .?. has been replaced by a
decimal number <v4>, and is calculated, using only the given conversion facts previously
given, so that the left and right-hand side quantities are equal. There should be a single space
between all elements in the line. The numbers <v3> and <v4> must be formatted as follows:
<v4> is greater than or equal to 1,000,000 or less than 0.1, it must be printed in scientific
notation: a number between 1.000000 and 9.999999 printed with exactly six digits after the
decimal point, followed by .e+nn. or .e-nn., where .e. represents .times ten to the power
of., and .nn. is a two digit number.
, <v4> must be printed in standard decimal notation, with a decimal point
followed by exactly six digits.
both cases, the number printed must be the closest such number to the true answer, i.e.
round, don.t truncate.
Sample Input:
7200.0 second = 2 hour
10.0 glob = 1 decaglob
1 day = 24.0 hour
1 minute = 60 second
1 glob = 10 centiglob
1 day = 24 hour
1 year = 365.25 day
50 centiglob = ? decaglob
5.6 second = ? hour
3 millisecond = ? hour
5.6 second = ? day
1 day = ? glob
1 hour = ? second
1 year = ? second
Sample Output (corresponding to sample input)
50.000000 centiglob = 0.500000 decaglob
5.600000 second = 1.555556e-03 hour
No conversion is possible.
5.600000 second = 6.481481e-05 day
No conversion is possible.
1.000000 hour = 3600.000000 second
1.000000 year = 3.155760e+07 second
 
M

mlimber

Gregory said:
Hello, Everybody!

Ok, I urgently need the solution for a following task in C++. This is the task from programmers contest,
so I believe somebody have a solution for it.
I need either a full source code or a simple description of algorithm to solve this task.
[snip]

As per FAQs 5.2 and 5.3, "Do it yourself. If you get stuck, ask a
specific question."

Cheers! --M
 
V

Victor Bazarov

Gregory said:
Ok, I urgently need the solution for a following task in C++. This is
the task from programmers contest, so I believe somebody have a
solution for it.
I need [..]

I think all those solutions are discussed in the FAQ 5.2.

V
 
O

osmium

Gregory Edigaroff said:
Ok, I urgently need the solution for a following task in C++. This is the
task from programmers contest,
so I believe somebody have a solution for it.
I need either a full source code or a simple description of algorithm to
solve this task.

thank a lot in advance.

Unit Conversion
A (measurement) unit is here represented by a single word containing only
lower-case letters. All
units are written as singular both in input and in output. A conversion
fact relates the size of two
units.
You are to convert a quantity in one unit to the equivalent quantity in a
different unit using only
a given set of conversion facts. These conversion facts are self
consistent; there is never more
than one conversion chain from any unit to any other unit.

<snip>
That doesn't sound like much of a contest to me. Where is the challenge?

global definiton:

struct Factoid
{
string name1;
string name2;
double k1;
double k2;
};

In main:
Factoid fa[100]; // factoid array

Not compiled.
If the operator is simply '=', add the data to the array. If it has a '?',
use the array to answer the question. Note that = works both ways, left to
right and right to left.
 
F

Frederick Gotham

Gregory Edigaroff posted:

thank a lot in advance.



#include <finances.hpp>
#include <professional_services\homework_completion.hpp>

int main()
{
Finances::SumOfMoney amount( 100, US_DOLLAR );

ProfessionalServices::Consultation cons(HOMEWORK);

if ( cons.ProposeFee( amount ).Accepted() )
{
cons.Proceed( CallbackFuncWhenCompleted );
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top