SOJ.Subtraction
来源:互联网 发布:720ccav新域名是什么 编辑:程序博客网 时间:2024/06/05 03:30
Subtraction
题目描述
某小朋友已经四岁了,她开始学习数字减法,但她还不理解负数的概念,如果被减数和减数中出现负数,或者被减数小于减数,她都不会算。
这里某人已设计函数calc做减法计算前进行了检查。
int calc(int a, int b) throw(logic_error)
{
if (a<0) throw out_of_range("Out of range exeception");
else if (b<0) throw out_of_range("Out of range exeception");
else if (a<b) throw logic_error("Minuend smaller than subtrahend");
return a-b;
}
请写一个test函数可以正确调用函数calc,test函数定义如下:
void test(int, int);
主函数也已给出如下:
#include <iostream>
#include <stdexcept>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
test(a, b);
}
return 0;
}
样例输入
43 1-3 11 -31 3
样例输出
2Out of range exceptionOut of range exceptionMinuend smaller than subtrahend
提示
请只提交test函数,不要提交calc函数。
0 0
- SOJ.Subtraction
- Subtraction
- soj
- String Subtraction
- string subtraction
- soj 1814
- SOJ-1012
- SOJ-1013
- SOJ-1015
- SOJ-1016
- SOJ-3327
- soj 3109
- { }soj.1206
- { }soj.2013
- SOJ-Dollars
- soj 1715
- soj 1681
- soj 6099
- iOS开发—06音频处理(音乐播放器6)
- 异常: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContex
- 第13周-项目1-小玩文件-用键盘输入文件名,统计输出类似下面的数据
- bzoj-1085 骑士精神
- VS1838B 红外接收头接线及单片机编码原理
- SOJ.Subtraction
- 实例分析Java Class的文件结构
- dataGrid 编辑 更新 删除 取消
- vs2010 中无法用qt设计师打开ui文件
- Combination Sum II
- C#中static void Main(string[ ] args)中的作用及解释
- Android-TextView
- SQL Server ISNULL函数和Coalesce函数替换空值的区别
- iOS开发网络数据之AFNetworking使用2.0和2.5