469,903 Members | 2,151 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

need your help (two urgent tasks)

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
--
With best regards,
Gregory Edigarov
Jun 14 '06 #1
4 1500
Gregory Edigaroff wrote:
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

Jun 14 '06 #2
Gregory Edigaroff wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 14 '06 #3
"Gregory Edigaroff" writes:
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.
Jun 14 '06 #4
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 );
}
}

--

Frederick Gotham
Jun 14 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by sunil | last post: by
3 posts views Thread by johnb41 | last post: by
1 post views Thread by karizmatrix22 | last post: by
2 posts views Thread by cj | last post: by
5 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.