Submit | All submissions | Best solutions | Back to list |
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
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 |
hide comments
|
|||||
2012-01-27 17:22:31 phpl0v3r
@author i KEEP getting SIGABRT. any idea why? #6405012 p.s. my code works. :| Re(Author): On running the test file, stderr gives : "terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at" Last edit: 2012-01-28 19:43:50 |
|||||
2011-12-27 16:03:58 Bharath Reddy
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.) Re(Author) : You forgot to add return statement + recheck with sample cases. Last edit: 2011-12-19 19:02:24 |
|||||
2011-12-27 16:03:58 .::Manish Kumar::.
Can you again tell,are we truncating or rounding like in %.6f . Thanks. EDIT : Okay I got AC.Actually we dont need to think all those things. Last edit: 2011-06-27 10:31:32 |
|||||
2011-12-27 16:03:58 Mateusz Drewienkowski
printf ("%f",0.0000005); returns 0 in C. Re(author): For such case answer should be 0.000000 Last edit: 2011-06-22 07:37:46 |
|||||
2011-12-27 16:03:58 XeRoN!X
@kiransk, check this http://ideone.com/uhMpH There are no escape sequences. |
|||||
2011-12-27 16:03:58 kiransk
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? also any of string/char types allow escape sequences (\" \' etc)? |
|||||
2011-12-27 16:03:58 cegprakash
nice problem |