10055 - Hashmat the Brave Warrior & 各数据类型所占字节数 (C语言)
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
______________________________________________
题目解答:
#include<stdio.h>
int main(){
long a,b,c;
while(scanf("%ld%ld",&a,&b) == ){
c = a - b;
if ( c < ) c = -c;
printf("%ld\n",c);
} return ;
}
注意点:
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\n",sizeof(short));
printf("signed int:%d\n",sizeof(signed int));
printf("unsigned int:%d\n",sizeof(unsigned int));
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 ;
}
运行结果得:
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位的
10055 - Hashmat the Brave Warrior & 各数据类型所占字节数 (C语言)的更多相关文章
- java基本数据类型所占字节数
JAVA基本数据类型所占字节数是多少?(32位系统) byte 1字节 short 2字节 int 4字节 ...
- 10055 - Hashmat the Brave Warrior
Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...
- 转:C/C++基本数据类型所占字节数
参考:http://blog.csdn.net/vast_sea/article/details/8076934 关于这个基本的问题,很早以前就很清楚了,C标准中并没有具体给出规定那个基本类型应该是多 ...
- C/C++基本数据类型所占字节数
关于这个主要的问题,非常早曾经就非常清楚了,C标准中并没有详细给出规定那个基本类型应该是多少字节数,并且这个也与机器.OS.编译器有关,比方相同是在32bits的操作系统系,VC++的编译器下int类 ...
- JAVA基本数据类型所占字节数是多少?
byte 1字节 short 2字节 int 4字节 long 8字节 ...
- C、C++数据类型所占字节数
C标准中并没有详细给出规定那个基本类型应该是多少字节数.详细与机器.OS.编译器有关,比方相同是在32bits的操作系统系,VC++的编译器下int类型为占4个字节:而tuborC下则是2个字节. 所 ...
- UVa 10055 - Hashmat the Brave Warrior
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...
- java 8种基本数据类型的默认值及所占字节数
通过一段代码来测试一下 8种基本数据类型的默认值 package dierge; public class Ceshi { int a; double b; boolean c; char d; fl ...
- java中8种数据类型和默认值所占字节数
java 8种基本数据类型的默认值及所占字节数 通过一段代码来测试一下 8种基本数据类型的默认值 1 package dierge; 2 3 public class Ceshi { 4 int a; ...
随机推荐
- KVM入门
KVM KVM(Kernel-based Virtual Machine)是众多虚拟化技术之一,它是Linux内核中的一个模块,该模块依赖于CPU,如果CPU支持虚拟化,那么该模块才可以被加载.KVM ...
- PHImageManager 获取图片模糊
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.synchronous = true; o ...
- jQuery源码分析--Event模块(3)
最后剩下了事件的手动触发了.jQuery提供了两个函数trigger和triggerHandler来手动触发事件,可以触发原生事件和自定义的事件.这个触发不单只会触发有jQuery绑定事件,而且也会触 ...
- 抓包工具Charles简单使用介绍
一是拦截别人软件的发送的请求和后端接口,练习开发. 二是自己后端返回的response拦截修改后再接收以达到测试临界数据的作用. 三写脚本重复拦截抓取别人的数据. 四支持流量控制,可以模拟慢速网络以及 ...
- 【转】微信jssdk录音功能开发记录
转自:http://www.cnblogs.com/liujunyang/p/4962423.html#undefined 0.需求描述 在微信浏览器内打开的页面,制作一个按钮,用户按住按钮后开始录音 ...
- Cooperation.GTST团队项目总结
Cooperation.GTST团队项目总结 项目实现情况 目前对于基本UI界面的设计已经实现,对博客园接口XML的解析也已经完成,但是还暂时无法动态获取对应数据. 几张静态预览图展示(侧滑栏设计加入 ...
- Access规格
属性 最大值 Microsoft Access 数据库 (.mdb) 文件大小 2G 字节减去系统对象所需的空间. 数据库中的对象个数 32,768 模块(包括“内含模块”属性为“是”的窗体和报表) ...
- 微信小程序路过——新手不要错过哦!
应该算是入门篇, 从我怎么0基础然后沿着什么方向走,遇到的什么坑,如何方向解决,不过本人接触不是很多,所以也就了解有限. 小程序的前提: 1.小程序大小不允许超过2M.(也就是本地图片,大图精图不要在 ...
- BZOJ 3527 【ZJOI2014】 力
题目链接:力 听说这道题是\(FFT\)板子题,于是我就来写了…… 首先可以发现这个式子:\[E_i=\sum_{j<i}\frac{q_j}{(i-j)^2}-\sum_{j>i}\fr ...
- python 哈希查找
import random INDEXBOX= #哈希表元素个数 MAXNUM= #数据个数 class Node: #声明链表结构 def __init__(self,val): self.val= ...