欢迎访问我的新博客:http://www.milkcu.com/blog/

原文地址:http://www.milkcu.com/blog/archives/uva10055.html

题目描述

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

___________________________________________________________________________________ 

Shahriar Manzoor

16-12-2000

解题思路

注意32位整数的范围,使用无符号整数或64位整数。 

一道非常简单的题,答案为什么总是错误的呢?

These two numbers in each line denotes the number of soldiers in Hashmat's army and his opponent's army orvice versa.

注意vice versa”,反之亦然。但是还是无法通过。

通过多次试验,发现绝对值函数abs()竟然在<algorithm> 头文件中。

代码实现

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void) {
long long a, b;
while(cin >> a >> b) {
cout << abs(b - a) << endl;
}
return 0;
}

(全文完)

Hashmat the brave warrior - UVa10055的更多相关文章

  1. Hashmat the brave warrior(UVa10055)简单题

    Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...

  2. 10055 - Hashmat the Brave Warrior

    Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...

  3. 10055 - Hashmat the Brave Warrior & 各数据类型所占字节数 (C语言)

    Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...

  4. UVa 10055 - Hashmat the Brave Warrior

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...

  5. 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 ...

  6. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

  7. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  8. UVa OJ 10055

    Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...

  9. 【索引】Volume 0. Getting Started

    AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 0. Getting Started 10055 - Hashmat the Brav ...

随机推荐

  1. ODP.NET 之访问 Oracle 数据库

    ODP.NET 之访问 Oracle 数据库 要相使用 Oracle Data Provider For .NET(ODP.NET), 必须先安装 ODP.NET 或者是 ODAC(Oracle Da ...

  2. zoj 2402 - Lenny&#39;s Lucky Lotto Lists

    称号:序列,在前面的每个元件的至少两倍,最大值至n.问:长l船舶有许多这样的. 分析:dp,LIS类别似事. 状态:f(i,j)结束数字为j且长度为i的序列的个数.有转移方程: F[ i ][ j ] ...

  3. javascript系列之DOM(一)

    原文:javascript系列之DOM(一) DOM(document object moudle),文档对象模型.它是一个中立于语言的应用程序接口(API),允许程序访问并修改文档的结构,内容和样式 ...

  4. ReactJS-render

    ReactJS分析之入口函数render ReactJS分析之入口函数render   前言 在使用React进行构建应用时,我们总会有一个步骤将组建或者虚拟DOM元素渲染到真实的DOM上,将任务交给 ...

  5. ROOT android 原理。 基于(zergRush)

    出自: http://bbs.gfan.com/android-2996211-1-1.html 须要ROOT的同学请去上面的地址下载. a.控制手机创建个暂时目录,然后把zergRush脚本写入此目 ...

  6. C#邮件收发

    public class Mail { private string mailkey; private string mailSecret; public string mailFrom; publi ...

  7. hive union all 使用

    功能:将两个表中的 同样的字段拼接到一起 測试: create external table IF NOT EXISTS temp_uniontest_ta ( a1 string, a2 strin ...

  8. 我们的空间是它圆——基于Poicare对宇宙的模型

    一般 状态 在人类文明的开始,并探讨了空间和时间的混乱从来没有停止过.马跑得更快.鱼下潜深.鸟振翅高飞,但是,人类并没有很深的不满潜飞不高.为什么?其原因是,马跑得更快,但它不会不知道他们为什么会跑得 ...

  9. Android锁定EditText内容和随机生成验证码

    昨天写了个小Demo,实现了随机生成验证码,和锁定EditText两个小功能,先看一下效果图: 锁定EditText在我们不须要用户编辑EditText内容的时候能够用到,实现还是非常easy的,一行 ...

  10. nginx的五种负载算法模式

    nginx 负载均衡5种配置方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight  指定轮询几率,weight和访问比率成正比 ...