OpenJudge1.4答案

01:判断数正负

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	long N;
	scanf("%ld",&N);
	if(N<0)
	{printf("negative");
	}
	else if(N==0)
	{printf("zero");
	}
	else
	{printf("positive");
	}
	return 0;
}

02:输出绝对值

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	float a;
	scanf("%f",&a);
	a*=100;
	a=abs((int)a);
	a/=100;
	printf("%.2f",a);
 
	return 0;
}

03:奇偶数判断

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int n;
	float m=0;
	scanf("%d",&n);
	m=n%2;
	if(m==1)
	{printf("odd");
	}
	else
	{printf("even");
	}
	
	return 0;
}

04:奇偶ASCII值判断

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	char c;
	scanf("%c",&c);
	if(c%2==0)
	{
		printf("NO");
	}
	else
	{
		printf("YES");
	}
	return 0;
}

05:整数大小比较

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	long a,b;
	scanf("%ld %ld",&a,&b);
	if(a>b)
	{
		printf(">");
	 } 
	else if(a==b)
	{
		printf("=");
	}
	else
	{
		printf("<");
	}
	return 0;
}

06:判断是否为两位数

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int a;
	scanf("%d",&a);
	a/=10;
	if((a<10)&&(a>=1))
	{
		printf("1");
	}
	else
	{
		printf("0");
	}

	return 0;
}

07:收集瓶盖赢大奖

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>=10)
	{
		printf("1");
	}
	else if(b>=20)
	{
		printf("1");
	}
	else
	{
		printf("0");
	}

	return 0;
}

08:判断一个数能否同时被3和5整除

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int n;
	scanf("%d",&n);
	if((n%5==0)&&(n%3==0))
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}

09:判断能否被3,5,7整除

#include <stdio.h>
#include<math.h>
int main()
{
	int a;
	int count=0,count3=0,count5=0,count7=0;
	scanf("%d",&a);
	if((a%3)==0)
	{
		count++;
		count3++;
	}
	if((a%5)==0)
	{
		count++;
		count5++;
	}
	if((a%7)==0)
	{
		count++;
		count7++;
	}
	if(count==3)
	{
		printf("3 5 7");
	}
	else if(count==2)
	{
		if(count3==0)
		{
			printf("5 7");
		}
		else if(count5==0)
		{
			printf("3 7");
		}
		else if(count7==0)
		{
			printf("3 5");
		}
	}
	else if(count==1)
	{
		if(count3==1)
		{
			printf("3");
		}
		else if(count5==1)
		{
			printf("5");
		}
		else if(count7==1)
		{
			printf("7");
		}
	}
	else if(count==0)
	{
		printf("n");
	}
}

10:有一门课不及格的学生

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int a,b,count=0;
	scanf("%d %d",&a,&b);
	if(a<60)
	{
		count++;
	}
	if(b<60)
	{
		count++;
	}	
	if(count==1)
	{
		printf("1");
	}
	else
	{
		printf("0");
	}
	return 0;
}

11:晶晶赴约会

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int a;
	scanf("%d",&a);
	if(0<a<8)
	{
		switch(a)
		{
			case 1:printf("NO");
			break;
			case 2:printf("YES");
			break;
			case 3:printf("NO");
			break;
			case 4:printf("YES");
			break;
			case 5:printf("NO");
			break;
			case 6:printf("YES");
			break;
			case 7:printf("YES");
			break;
		}
	}
	return 0;
}

12:骑车与走路

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int s;
	float t1,t2,v1=1.2,v2=3.0;
	scanf("%d",&s);
	t1=s/v1;
	t2=(s/v2)+50;
	if(t1>t2)
	{
		printf("Bike");
	}
	else if(t2>t1)
	{
		printf("Walk");
	}
	else
	{
		printf("All");
	}
	return 0;
}

13:分段函数

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	float x=0,y;
	scanf("%f",&x);
	if((x>=0)&&(x<20))
	{
		if((x>=0)&&(x<5))
		{
			y=-x+2.5;
			printf("%.3f",y);
		}
		else if((x>=5)&&(x<10))
		{
			y=2-1.5*pow((x-3),2);
			printf("%.3f",y);
		}
		else
		{
			y=(x/2)-1.5;
			printf("%.3f",y);
		}
	}
	return 0;
}

14:计算邮资

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int g,m;
	char s;
	scanf("%d %c",&g,&s);
	if(g<=1000)
	{
		m=8;
	}
	else(g>1000);
	{
		g=(int)ceil((g-1000)/500.0);
		m=(g*4)+8;
	}
	switch(s)
	{
		case 'y':m+=5;
		break;
		case 'n':m;
		break;
	}
	printf("%d",m);
	return 0;
}

15:最大数输出

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b)
	{
		if(a>c)
		{
			printf("%d",a);
		}
		else
		{
			printf("%d",c);
		}
	}
	else
	{
		if(b>c)
		{
			printf("%d",b);
		}
		else
		{
			printf("%d",c);
		}
	}
	return 0;
}

16:三角形判断

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if((a+b>c)&&(a+c>b)&(b+c>a))
	{
		printf("yes");
	}
	else
	{
		printf("no");
	}
	return 0;
}

17:判断闰年

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int year,middle=0;
	char result;
	scanf("%d",&year);
	if(year%4==0)
	{
		middle=1;	
		

	if((year%100==0)&&(year%400!=0)||(year%3200)==0)
	{
		middle=0;
	}
	else
	{
		middle=1;
	}
}
	switch(middle)
	{
		case 1:result='Y';
		break;
		case 0:result='N';
		break;
	}
	printf("%c",result);
	return 0;
}

18:点和正方形的关系

#include <stdio.h>

int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if((x<=1)&&(x>=-1)&&(y<=1)&&(y>=-1))
	printf("yes");
	else 
	printf("no");
	return 0;
}

19:简单计算器

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int a,b,answer;
	char symbol;
	scanf("%d %d %c",&a,&b,&symbol);
	if(b==0)
	{
		printf("Divided by zero!");
		return 0;
	}
	if((symbol!='+')&&(symbol!='-')&&(symbol!='*')&&(symbol!='/'))
	{
		printf("Invalid operator!");
		return 0;
	}
	switch(symbol)
	{
		case '+':answer=a+b;
		break;
		case '-':answer=a-b;
		break;
		case '*':answer=a*b;
		break;
		case '/':answer=a/b;
	}
	
	printf("%d",answer);
	
	
	return 0;
}

20:求一元二次方程的根

#include <stdio.h>
#include<math.h>
int main()
{
	double a,b,c,deta;
	double x1,x2;
	scanf("%lf %lf %lf",&a,&b,&c);
	deta=b*b-4*a*c;
	if(deta==0)
	{
		x1=(-b+sqrt(b*b-4*a*c))/(2*a);
		if(b==0)
		{
			x1=-x1;
		}
		printf("x1=x2=%.5f",x1);
	}
	else if(deta>0)
	{
		x1=(-b+sqrt(b*b-4*a*c))/(2*a);
		x2=(-b-sqrt(b*b-4*a*c))/(2*a);
		printf("x1=%.5f;x2=%.5f",x1,x2);
	}
	else if(deta<0)
	{
		x1=-b/(2*a);
		x2=sqrt(4*a*c-b*b)/(2*a);
		if(b==0)
		{
			x1=-x1;
		}
		printf("x1=%.5f+%.5fi;x2=%.5f-%.5fi",x1,x2,x1,x2);
	}
}

21:苹果和虫子2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int n,x,y,answer;
	scanf("%d %d %d",&n,&x,&y);
	answer=n-ceil(y*1.0/x);
	if(answer<=0)
	{
		printf("0");
	}
	else
	{
	printf("%d",answer);
	}
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值