zoukankan      html  css  js  c++  java
  • 2013 gzhu 校赛

    题目描述:

                  Integer in C++

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others)

    Problem Description

      KIDx: I like Java much more than C++, because I can use BigInteger in Java. :)

    However, KIDx has to use C++ language to do a project...

    Little KIDx knows 3 integer types in C++:

    1) short occupies 2 bytes and allows you to store numbers from -32768 to 32767

    2) int occupies 4 bytes and allows you to store numbers from -2147483648 to 2147483647

    3) long long occupies 8 bytes and allows you to store numbers from -9223372036854775808 to 9223372036854775807

    For all the types given above the boundary values are included in the value range. From this list, KIDx wants you to choose the smallest type that can store a positive integer n.

    Input

      Each case contains a positive integer n. It consists of at least one digit and at most 30 digits. In addition, it doesn't contain any leading zeros.

    Output

      For each line, print the first type from the list "short, int, long long", that can store the natural number n. If no one can store the number, just print "It is too big!".

    Sample Input

    102
    50000
    123456789101112131415161718192021222324

    Sample Output

    short
    int
    It is too big!

    简单字符串处理,留作纪念!!!
    竟然忘记了strcmp这个函数的强大功能,它的比较是按ASCII码表的。
     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <cstdlib>
     5 using namespace std;
     6 
     7 const int maxn = 30 + 10;
     8 char s[maxn], t[maxn];
     9 
    10 int main()
    11 {
    12      int i, len;
    13      while (gets(s))
    14      {
    15          len = strlen(s);
    16          if (s[0] == '-')
    17          {
    18              int l = 0;
    19              for (i = 1; i < len; i++)
    20                  t[l++] = s[i];
    21              if ((strcmp(t, "32768") <= 0 && l == strlen("32768")) || l < strlen("32768"))
    22                  puts("short");
    23              else if ((strcmp(t, "2147483648") <= 0 && l == strlen("2147483648")) || l < strlen("2147483648"))
    24                  puts("int");
    25              else if ((strcmp(t, "9223372036854775808") <= 0 && l == strlen("9223372036854775808")) || l < strlen("9223372036854775808") )
    26                  puts("long long");
    27              else
    28                  puts("It is too big!");
    29          }
    30          else
    31          {
    32              if ((strcmp(s, "32767") <= 0 && len == strlen("32767")) || len < strlen("32767"))
    33                  puts("short");
    34              else if ((strcmp(s, "2147483647") <= 0 && len == strlen("2147483647")) || len < strlen("2147483647"))
    35                  puts("int");
    36              else if ((strcmp(s, "9223372036854775807") <= 0  && len == strlen("9223372036854775807")) || len < strlen("9223372036854775807"))
    37                  puts("long long");
    38              else
    39                  puts("It is too big!");
    40          }
    41      }
    42     return 0;
    43 }
  • 相关阅读:
    [转]在nodejs使用Redis缓存和查询数据及Session持久化(Express)
    [转]最常用的商务职场英语邮件100个句式
    [转]玩转Angular2(4)--制作左侧自动定位菜单
    [转]Angular开发(十八)-路由的基本认识
    Consul之:服务注册与发现
    Consul之:key/value存储
    服务容错保护断路器Hystrix之六:服务熔断和服务降级
    延时队列:Java中的DelayQueue
    分布式延迟消息队列实现分析与设计
    基于redis的延迟消息队列设计
  • 原文地址:https://www.cnblogs.com/windysai/p/3633665.html
Copyright © 2011-2022 走看看