zoukankan      html  css  js  c++  java
  • 10055

    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 #include<stdio.h>
     2 int main(){
     3     long a,b,c; 
     4     while(scanf("%ld%ld",&a,&b) == 2){
     5         c = a - b;
     6         if ( c < 0) c = -c;
     7         printf("%ld
    ",c);
     8     }
     9 
    10     return 0;   
    11 }

    注意点:

    1.  输入的数据不大于2^32,32位系统或者是64位使用的int的表示范围为(-2^31)~(2^31-1)。使用long

    2.  使用long可以accept,UVa平台使用的是64位的。在32位系统中long也是占4字节,不满足题目要求。

    获取各数据类型所占字节数:我的电脑为64位的系统上:(使用sizeof(int))

    #include<stdio.h>
    
    int main(){
        printf("short:%d
    ",sizeof(short));
        printf("signed int:%d
    ",sizeof(signed int));
        printf("unsigned int:%d
    ",sizeof(unsigned int));
        printf("long:%d
    ",sizeof(long));
        printf("long long:%d
    ",sizeof(long long));
        printf("double:%d
    ",sizeof(double));
        printf("float:%d
    ",sizeof(float));
    
        return 0;
        
    }

    运行结果得:

      short:2; int:4;unsigned int:4;long:8;long long:8;double:8;float:4

     

    BTW:

    MAC上面查看系统32还是64位的命令:

    1.  在终端输入命令   ioreg -l -p IODeviceTree | grep "firmware-abi" | sed -e 's/[^0-9A-Z]//g'

       输出:EFI64 ——64位
       输出:EFI32 ——32位

    2.  打开终端,输入命令 uname -a 回车

      x86_64 ——64位

      i686 ——表示系统32位的

  • 相关阅读:
    基于Metaweblog API 接口一键发布到国内外主流博客平台
    uva144 Student Grants
    Uva 10452
    Uva 439 Knight Moves
    Uva 352 The Seasonal War
    switch语句
    java——基础知识
    我的lua学习2
    codeforces 431 D. Random Task 组合数学
    codeforces 285 D. Permutation Sum 状压 dfs打表
  • 原文地址:https://www.cnblogs.com/fyymonica/p/4162643.html
Copyright © 2011-2022 走看看