PRINTF - Printf Parser
In this task you have to parse a C language printf statement and print the output that will be produced on executing that statement in C. The statement will be of type printf("A",A1,A2,A3.....); where A consists of small latin alphabets, whitespaces and following format specifiers ( whitespaces will be present only in A ):
%d - signed decimal integer
%c - character
%f - decimal floating point( 6 digits after decimal point )
%s - character string
A1, A2, A3 ... are the arguments passed to printf statement and they will be equal to number of format specifiers mentioned. Their argument type will be same as that of format specifier i.e if specfier is '%c' the corresponding argument will be a character only. Input will always have at least one format specifier.
Input
First line of input contains a positive integer T denoting number of test cases. Following T lines have a valid printf statment containing less than 500 characters.
Output
Print the corresponding output given by the printf statement.
Example
Input:
2
printf("%c %d%f",'L',123,4.5);
printf("hello %f world %d nice %f computer %c is easy %s",2.34123245231,100,1.41414141,'S',"problem");
Output:
L 1234.500000
hello 2.341232 world 100 nice 1.414141 computer S is easy problem
Score : Source Code Length
hide comments
phpl0v3r:
2012-01-27 17:22:31
@author
|
|
Bharath Reddy:
2011-12-27 16:03:58
My code works fine for the given inputs on my computer. But the judge says "run time error(NZEC)". Can anyone help?(Provide me some additional test cases etc.)
|
|
.::Manish Kumar::.:
2011-12-27 16:03:58
Can you again tell,are we truncating or rounding like in %.6f .
|
|
Mateusz Drewienkowski:
2011-12-27 16:03:58
printf ("%f",0.0000005); returns 0 in C.
|
|
XeRoN!X:
2011-12-27 16:03:58
@kiransk, check this http://ideone.com/uhMpH
|
|
kiransk:
2011-12-27 16:03:58
last test has float value of 2.341232, but default behavior of printf would result in 2.341233 (round). do you expect truncation instead of rounding?
|
|
cegprakash:
2011-12-27 16:03:58
nice problem |
Added by: | XeRoN!X |
Date: | 2011-02-24 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | C C++ 4.3.2 CPP |