游客 Signup | Login
中文 | En

1823 - 课后习题5.5

有一个函数

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>
int main(void)
{
	int x;
	scanf("%d",&x);
	if(x<1)
		printf("%d\n",x);
	else
	{
	if(x>=10)
		printf("%d\n",3*x-11);
	else
		printf("%d\n",2*x-1);
	}
	return 0;
}

Solution C++

#include<bits/stdc++.h>
using namespace std;
int x,y;
int main()
{
	cin>>x;
	if(x<1)y=x;
	else if(1<=x&&x<10)y=2*x-1;
	else if(x>=10)y=3*x-11;
	cout<<y;
   	return 0;
}

Hint

使用函数

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