Problem 2: Datatype
Time limit: 2 secs
Write a program to find whether the given string is an integer, floating point or character string.
Assume that an integer is only of the form x1x2x3..xn(e.g. 12345678) , float is of the form x1x2..xn(.)a1a2a3..am (e.g 123.34)and all other remaining forms are character strings, where x1,x2,x3...xn and a1,a2...an are digits from 0 to 9. There can be leading + or - in integers and floats.
Output INT for integer, FLOAT for floating point and CHAR for characters or strings.
First line of input will contain the number of test cases 't'.
Next t lines will contain one string each.
For each input,output INT,FLOAT or CHAR on a new line.
Each string will be of length less than 30 and will not contain any space.
3 23 -34.3 we2
INT FLOAT CHAR
USE OF FUNCTIONS IN "math.h" IS NOT ALLOWED
K = Number of keywords
C = Number of non-whitespace characters
T = 50000/(C+K)
The only approach to solve the problem is minimize the number of characters and keywords using any C-concepts which can be mustered. Only care to be taken is that the checking of integers and floating point is done properly according to the criteria specified in problem. For removing loop keywords, we can can use recursion. Conditional keywords can be removed using logical operators. int can be removed by declaring them globally or as main arguments.
Reference:2.2 Data Types and Sizes, Dennis Ritchie
Check the Best Solutions
Submit your solution
You need to be logged in to submit a solution.
|Q:||Do the digits in a FLOAT/INT have to be in ascending order??|
|bashrc||is there a test case like x1x2x3.x4x5x6.x7x8x9|
|Q:||if yes then what it should be?float or char?|
|A:||it will be char|
|cegprakash||one more doubt|
|Q:||is +5 is an integer?? is +5.0 is a float?|
|A:||+5 is an integer\r\n+5.0 is a float|
|Q:||-1.0\\nis float as given\\n-123 is an INT???|
|Q:||123. is float or char？\\nWhat about 0123？|
|A:||123. is CHAR and 0123 is INT|
|Q:||Is puts and gets allowed in gcc ?|
|Q:||+++++5.00 is float or char??|
|A:||this is CHAR|
|Pband||What if input string is empty?|
|Q:||What if input string is empty?|
|A:||Input string won\'t be empty|
|Q:||Can n or m be zero? Can they be less than 3?|
|A:||n and m cannot be 0 but can be less than 3|
|Q:||1) .5 is float? (can be x is omitted in floats?)\\n2) can be trailing zeros? 0005 is INT or CHAR?\\n3) 5. is float? (can be a is omitted in floats?)|
|A:||.5 is not considered as float but 0.5 is float. 0005 is INT. 5. is CHAR|
|Q:||\"Assume that an integer is only of the form x1x2x3..xn(e.g. 12345678), float is of the form x1x2..xn(.)a1a2a3..am (e.g 123.34)and all other remaining forms are character strings, where x1,x2,x3...xn and a1,a2...an are digits from 0 to 9.There can be leading + or - in integers and floats.1) does this mean for INT and FLOAT x1 may be + or -, effectively making the following statement untrue? where x1,x2,x3...xn and a1,a2...an are digits from 0 to 9.2) How should we treat two strings_without_spaces separated by a whitespace on a line? Should I treat them as a single CHAR or treat each of them separately?|
|A:||No line will contain strings separated by whitespace|
post a question