游客 Signup | Login
中文 | En

1411 - C语言-分段函数

有一个函数

y={ x      x<1
    | 2x-1   1<=x<10
    \ 3x-11  x>=10

写一段程序,输入x,输出y

Input

一个数x

Output

一个数y

Examples

Input

14

Output

31

Hint

使用函数

Solution C

#include<stdio.h>
void main()
{
	int x,y;
	scanf("%d",&x);
	if(x<1)
		y=x;
	else if(1<=x&&x<10)
		y=2*x-1;
	else
		y=3*x-11;
	printf("%d\n",y);
}

Solution C++

#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
	//ifstream cin("aaa.txt");
	int i,j,n,m,x1,x2,x3,x4,len;
	cin>>n;
	if(n<1) cout<<n;
	else if(n<10) cout<<2*n-1;
	else cout<<3*n-11;
	cout<<endl;
	


return 0;
}
	

Hint

使用函数

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题