Judge the data type (10 points) [C language foundation]

Judge the data type (10 points)

Description

Suppose now you want to determine whether the data type is int, long long, double, and input n strings, please determine what the data type it represents, and each string input is guaranteed to be a positive number and be of these three types Kind of.

Input

An integer n in the first line. (N<=10)

One string s per line for the next n lines. (|s|<=10)

Output

For each string s, output "int" or "long long" or "double".

Sample Input 1 

3
12
9999999999
123.44

Sample Output 1

int
long long
double

Analysis: Thank you QSH hahaha.

#include <stdio.h>
#include <string.h>
//#include <climits>
//#include <iostream>
//#include <cstdio>
//#include <cstring>
//#include <bits/stdc++.h>
//#include <queue>
//#include <algorithm>
//#include <map>
//#include <cstdlib>
//using namespace std;
#define inf 0x3f3f3f3f
char a[100000];
int main()
{
    int n,sb;
    double x;
    scanf("%d", &n);
    while(n --){
        scanf("%s",a);
        int len = strlen(a);
        int flag=0;

        for(int i = 0; i < len; i ++){
            if(a[i] == '.'){
                flag = 1;break;
            }
        }
        if(flag==1)printf("double\n");
        else {
            long long x = 0;
            long long cnt = 1;
            if(a[0] =='-') sb = 1;
            else sb = 0;
            for(int i = len - 1; i >= sb; i --){
                x += cnt * (int)(a[i] -'0');
                cnt *=10;
            }
            if(sb == 1) x *= -1;
            if(x >  2147483647 || x < -2147483648)printf("long long\n");
            else printf("int\n");
        }
    }

    return 0;
}

 

Guess you like

Origin blog.csdn.net/Mercury_Lc/article/details/107140745
Recommended