SOJ.Subtraction

来源:互联网 发布:720ccav新域名是什么 编辑:程序博客网 时间:2024/06/05 03:30
Subtraction
       
    
时间限制:1秒    内存限制:256兆
题目描述

某小朋友已经四岁了,她开始学习数字减法,但她还不理解负数的概念,如果被减数和减数中出现负数,或者被减数小于减数,她都不会算。

这里某人已设计函数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