zoukankan      html  css  js  c++  java
  • Hashmat the brave warrior(UVa10055)简单题

    Problem A

    Hashmat the brave warrior

    Input: standard input

    Output: standard output

    Hashmat is a brave warrior who with his group of young soldiers moves from one place to another to fight against his opponents. Before fighting he just calculates one thing, the difference between his soldier number and the opponent's soldier number. From this difference he decides whether to fight or not. Hashmat's soldier number is never greater than his opponent.

    Input

    The input contains two integer numbers in every line. These two numbers in each line denotes the number of soldiers in Hashmat's army and his opponent's army or vice versa.(反之亦然。。。) The input numbers are not greater than 2^32. Input is terminated by End of File.

    Output

     For each line of input, print the difference of number of soldiers between Hashmat's army and his opponent's army. Each output should be in seperate line.

     

    Sample Input:

    10 12

    10 14

    100 200

     

    Sample Output:

    2

    4

    100

    注意:

    1.  vice versa  译为 反之亦然
    2.  用c++ 提交  int64 不能被识别 会有编译错误。。。。PE两次。。
    3.  用 long 或 long long 或者 double 类型 都可以满足数据 范围

    #include<stdio.h>
    //vice versa反之亦然,坑爹!还有为啥int64不能用?
    int main()
    {
        long a,b;
        while(scanf("%ld%ld",&a,&b)!=EOF)
        {
            if(b>a)
                printf("%ld
    ",(b-a));
            else
                printf("%ld
    ",(a-b));
        }
        return 0;
    }
    
    这道题我可耻的错了3次,真心跪了,有一个陷阱:
    
    我坚定的认为 unsigned int 能够实现2^32 !!!!
    事实上,这是错的,unsigned int 的确能够代表 2^32个数,但是最高的那个数是 2^32-1。所以应该要用long long,但是不知道为什么long 也可以,原来
    C++标准只规定int型数据所占的字节数不大于long型,不小于short型。
    16位平台                   32位平台                    64位平台   
    char 1个字节8位         char 1个字节8位             char 1个字节8位   
    short 2个字节16位       short 2个字节16位           short 2个字节16位
    int 2个字节16位         int 4个字节32位             int 4个字节32位
    long 4个字节32位        long 4个字节32位            long 8个字节64位
    指针 2个字节            long long 8个字节64位    long long 8个字节64位
                         指针 4个字节32位          指针 8个字节 64位      
    
    所以用哪个数据类型,得自己掂量掂量。幸好这个Uva是用64位的系统,否则我的long又得WA一次。
    总结:(1)看清楚题目,认真学习英语:vice versa == 反之亦然
          (2)unsigned int 能代表2^32个数,但是最高的那个数是2^32-13long long 是linux 下的,int64是windows下的,一般的OJ是linux下run  
    View Code
  • 相关阅读:
    Wix Burn:如何将32位和64位的安装包制作成一个安装包
    禁止32位安装包运行在64位操作系统上
    图片校验码
    Oracle建表命令
    npm系列
    git使用
    syslog
    hibernate配置enum枚举属性
    httpClient发送post请求
    修改ubuntu系统语言
  • 原文地址:https://www.cnblogs.com/yuyixingkong/p/3515991.html
Copyright © 2011-2022 走看看