Problem B: 求(x-y+z)*2

Description

编写一个程序,求解以下三个函数:
f(x,y,z)=2*(x-y+z)
f(x,y)  =2*(x-y)
f(x)    =2*(x-1)
函数调用格式见append.cc。
append.cc中已给出main()函数。

Input

输入的测试数据为多组。每组测试数据的第一个数是n(1<=n<=3),表示后面有n个整数。
当n为3时,后跟3个输入为x,y,z;
当n为2时,后跟2个输入为x,y;
当n为1时,后跟1个输入为x;
当n为0时,表示输入结束
输入的n不会有其他取值。
所有运算都不会超出int类型范围。

Output

每组测试数据对应一个输出。输出x-y+z的值。

Sample Input

3 121 38 45
2 39 11
1 73

Sample Output

256
56
144

HINT

Append Code

#include<iostream>
using namespace std;
int f( int &x, int &y, int &z)
{
     return 2*(x-y+z);
}
int f( int &x, int &y)
{
     return 2*(x-y);
}
int f( int &x)
{
     return 2*(x-1);
}
 
int main()
{
     int n, x, y, z;
     while (cin>>n)
     {
         if (n == 3)
         {
             cin>>x>>y>>z;
             cout<<f(x, y, z)<<endl;
         }
         if (n == 2)
         {
             cin>>x>>y;
             cout<<f(x, y)<<endl;
         }
         if (n == 1)
         {
             cin>>x;
             cout<<f(x)<<endl;
         }
         if (n == 0)
             break ;
     }
}

转载于:https://www.cnblogs.com/TogetherLaugh/p/6544601.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值