10055-hashmat the Brave Warrior & number of bytes per data type (C language)

Source: Internet
Author: User

Problem A

Hashmat the Brave Warrior

Input: Standard Input

Output: Standard Output

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


Input

The input contains the numbers in every line. These the numbers in each line denotes the number of soldiers in Hashmat's army and his opponent ' s army or vice versa. The input numbers is 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 is in the seperate line.

Sample Input:

10 12
10 14
100 200

Sample Output:

2
4
100

______________________________________________

Topic Answer:

1#include <stdio.h>2 intMain () {3     Long a,b,c;4      while(SCANF ("%ld%ld", &a,&b) = =2){5c = A-b;6         if(C <0) C =-C;7printf"%ld\n", c);8     }9 Ten     return 0;  One}

Note the point:

1. The input data is not more than the 2^32,32-bit system or the 64-bit used int represents a range of ( -2^31) ~ (2^31-1). Use long

2. A long can be used to accept,uva the platform using 64-bit. Long also accounts for 4 bytes in 32-bit systems and does not meet the requirements of the topic.

Get the number of bytes per data type: My computer is on a 64-bit system: (using sizeof (int))

#include <stdio.h>intMain () {printf ("short:%d\n",sizeof( Short)); printf ("signed int:%d\n",sizeof(Signedint)); printf ("unsigned int:%d\n",sizeof(unsignedint)); printf ("long:%d\n",sizeof(Long)); printf ("Long long:%d\n",sizeof(Long Long)); printf ("double:%d\n",sizeof(Double)); printf ("float:%d\n",sizeof(float)); return 0; }

The result of the operation was:

Short:2, int:4;unsigned Int:4;long:8;long long:8;double:8;float:4

BTW:

On Mac, look for system 32 or 64-bit commands:

1. In Terminal input command Ioreg-l-P iodevicetree | grep "Firmware-abi" | Sed-e ' s/[^0-9a-z]//g '

Output: efi64--64 bit
Output: efi32--32 bit

2. Open terminal, enter command uname-a return

X86_64--64 bit

The i686--represents the system 32-bit

10055-hashmat the Brave Warrior & number of bytes per data type (C language)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.