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.
Input:
First line of input will contain the number of test cases 't'.
Next t lines will contain one string each.
Output:
For each input,output INT,FLOAT or CHAR on a new line.
Constraints:
0<t<70
Each string will be of length less than 30 and will not contain any space.
Sample Input:
3
23
-34.3
we2
Sample Output:
INT
FLOAT
CHAR
Scoring:
USE OF FUNCTIONS IN "math.h" IS NOT ALLOWED
K = Number of keywords
C = Number of non-whitespace characters
T = 50000/(C+K)
Solution:
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
discussions
| iCodeNano | order |
| Q: | Do the digits in a FLOAT/INT have to be in ascending order?? |
| A: | No. |
| 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 |
| cegprakash | doubt |
| Q: | -1.0\\nis float as given\\n-123 is an INT??? |
| A: | Yes |
| tjuzcfc | float |
| Q: | 123. is float or char?\\nWhat about 0123? |
| A: | 123. is CHAR and 0123 is INT |
| titasde08 | regarding q2 |
| Q: | Is puts and gets allowed in gcc ? |
| A: | yes |
| saurabhkr_1989 | float |
| Q: | +++++5.00 is float or char?? |
| A: | this is CHAR |
| dolphinigle | Empty String |
| Q: | allowed? |
| A: | no |
| Pband | What if input string is empty? |
| Q: | What if input string is empty? |
| A: | Input string won\'t be empty |
| al13n321 | empty numbers |
| 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 |
| cmds | Float |
| 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 |
| dolphinigle | Clarification |
| 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
Loading...
If you have a doubt about this problem, and don't find it listed in the discussion above, post it here.
If we think your question is relevant to everybody, we'll publish it to the discussion. Otherwise, we'll send you a private reply via email.
To post question you need to login.