欢迎访问我的新博客: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. 浅谈SQL注入风险 - 一个Login拿下Server(转)

    前两天,带着学生们学习了简单的ASP.NET MVC,通过ADO.NET方式连接数据库,实现增删改查. 可能有一部分学生提前预习过,在我写登录SQL的时候,他们鄙视我说:“老师你这SQL有注入,随便都 ...

  2. rabbitMQ说明文档

    rabbitMQ是什么 RabbitMQ     是由     LShift     提供的一个     Advanced Message Queuing Protocol (AMQP)     的开 ...

  3. C++语言债券系列之十一——友元函数和拷贝构造函数

    1.好友功能 (1)友元函数类的普通功能外定义. 定义友元函数和相同的正常功能.在类必须声明的正常功能为好友. (2)友元函数不是一个成员函数. 你不能反对打电话.但直接调用:友元函数访问类的公共.p ...

  4. 读取xml文件"分析 EntityName 时出错"的解决方案

    在涉及到xml与xslt编程的过程中,经常会碰到"分析 EntityName 时出错"的提示,这个不是程序错误,是因为xml文件中使用了一些特殊符号导致的.    XML 节点中不 ...

  5. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(20)-多条件模糊查询和回收站还原的实现

    原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(20)-多条件模糊查询和回收站还原的实现 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架 ...

  6. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(17)-注册用户功能的细节处理(各种验证)

    原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(17)-注册用户功能的细节处理(各种验证) ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框 ...

  7. ssh 综合

    文件夹结构: 搭建项目: 1.创建web项目 2.创建各种包. com.atguigu.surveypark.dao.impl com.atguigu.surveypark.model com.atg ...

  8. 【淡墨Unity3D Shader计划】四 热带雨林的文章: 排除、深度测试、Alpha测试和基本雾编译

    本系列文章由@浅墨_毛星云 出品,转载请注明出处.   文章链接:http://hpw123.net/a/C__/kongzhitaichengxu/2014/1222/163.html 作者:毛星云 ...

  9. 用HMM(隐马)图解三国杀的于吉“质疑”

    ·背景 最近乘闲暇之余初探了HMM(隐马尔科夫模型),觉得还有点意思,但是网上的教程都超级枯草,可读性很差,抄来抄去的,一堆公式仍在你面前,谁能搞的懂(但园内的两篇写的还算不错.真才实学).在熬制3天 ...

  10. hdu 4932 Miaomiao&#39;s Geometry(暴力)

    题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...