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\n",(b-a));
else
printf("%ld\n",(a-b));
}
return ;
} 这道题我可耻的错了3次,真心跪了,有一个陷阱: 我坚定的认为 unsigned int 能够实现2^ !!!!
事实上,这是错的,unsigned int 的确能够代表 ^32个数,但是最高的那个数是 ^-。所以应该要用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一次。
总结:()看清楚题目,认真学习英语:vice versa == 反之亦然
()unsigned int 能代表2^32个数,但是最高的那个数是2^-
()long long 是linux 下的,int64是windows下的,一般的OJ是linux下run
Hashmat the brave warrior(UVa10055)简单题的更多相关文章
- Hashmat the brave warrior - UVa10055
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10055.html 题目描述 Pr ...
- 10055 - Hashmat the Brave Warrior
Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...
- 10055 - Hashmat the Brave Warrior & 各数据类型所占字节数 (C语言)
Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...
- UVa 10055 - Hashmat the Brave Warrior
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...
- UVA_10055:Hashmat the brave warrior
Language:C++ 4.8.2 #include<stdio.h> int main(void) { long long int a, b; while(scanf("%l ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
随机推荐
- Java基础巩固——反射
什么是反射 反射机制就是指程序运行时能够获取自身的信息.在Java中,只要给出类的名字,就可以通过反射机制来获取类的信息 哪里用的到反射机制 在jdbc中就是使用的反射来实例化对象,比如:Class. ...
- urllib2 的使用与介绍
爬虫简介 什么是爬虫? 爬虫:就是抓取网页数据的程序. HTTP和HTTPS HTTP协议(HyperText Transfer Protocol,超文本传输协议):是一种发布和接收 HTML页面的 ...
- C语言Socket-模拟远程CMD(客户端向服务器发送命令,服务器执行该命令)
服务端(server) #include <stdio.h> #include <winsock2.h> #pragma comment(lib,"ws2_32.li ...
- [WC2005]双面棋盘(线段树+并查集)
线段树+并查集维护连通性. 好像 \(700ms\) 的时限把我的常数超级大的做法卡掉了, 必须要开 \(O_2\) 才行. 对于线段树的每一个结点都开左边的并查集,右边的并查集,然后合并. \(Co ...
- mybatis四大接口之 StatementHandler
1. 继承结构 StatementHandler:顶层接口 BaseStatementHandler : 实现顶层接口的抽象类,实现了部分接口,并定义了一个抽象方法 SimpleStatementHa ...
- mybatis四大接口之 Executor
[参考文章]:Mybatis-Executor解析 1. Executor的继承结构 2. Executor(顶层接口) 定义了执行器的一些基本操作: public interface Executo ...
- Docker - Docker与Vagrant的区别
Docker Docker - HomePage Wiki - Docker Docker简介 Overview Docker 是一个开源的应用容器引擎,基于 Go 语言并遵从 Apache2.0 协 ...
- 用开源 ASP.NET MVC 程序 Bonobo Git Server 搭建 Git 服务器(转)
用开源 ASP.NET MVC 程序 Bonobo Git Server 搭建 Git 服务器 现在不用Git,都不好意思说自己是程序员. 当你想用Git,而源代码服务器是Windows系统时,你 ...
- [原创]EF架构随心所欲打造属于你自己的DbModel
前言 我们都知道EF可以生成Dbmodel,系统生成的Model有时候并不是我们想要的,如何我们要生成自己的Model,那么久需要我们手动的去修改T4模版,T4是对“Text Template Tra ...
- JavaScript基础(一)概述
JavaScript 概述 JS作用 验证表单(以前的网速慢) 页面特效(PC端的网页效果) 移动端(移动web和app) 异步和服务器交互(AJAX) 服务端开发(nodejs) 语言类型 js是一 ...