前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >判断数据类型(10分)【 C语言基础 】

判断数据类型(10分)【 C语言基础 】

作者头像
Lokinli
发布2023-03-09 13:59:30
3340
发布2023-03-09 13:59:30
举报
文章被收录于专栏:以终为始

判断数据类型(10分)

Description

假设现在你要判断数据类型是否为int、long long、double,输入n个字符串,请你判断其代表的数据类型是什么,且输入的每个字符串保证是正数,且是这三种类型的一种。

Input

第一行一个整数n。(n<=10)

接下来n行每行一个字符串s。(|s|<=10)

Output

对于每个字符串s,输出“int”或“long long”或“double”。

Sample Input 1 

代码语言:javascript
复制
3
12
9999999999
123.44

Sample Output 1

代码语言:javascript
复制
int
long long
double

解析:感谢QSH哈哈哈。

代码语言:javascript
复制
#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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-07-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 判断数据类型(10分)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档