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

来源:互联网 发布:tm域名查询 编辑:程序博客网 时间:2024/05/16 17:05

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

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2663  Solved: 2293
[Submit][Status][Web Board]

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 452 39 111 73

Sample Output

25656144

HINT

Append Code

append.cc,
[Submit][Status][Web Board]
한국어<  中文 فارسی English ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#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;    }} 

0 0
原创粉丝点击