Openjudge1.4答案
01
#include <stdio.h>
int main()
{
long a;
scanf("%ld",&a);
if(a==0)
{
printf("zero");
}
else if(a>0)
{
printf("positive");
}
else
{
printf("negative");
}
return 0;
}
02
#include <stdio.h>
#include<math.h>
int main()
{
double a;
scanf("%lf",&a);
a*=100;
a=abs((int)a);
a/=100;
printf("%.2f",a);
return 0;
}
03
#include <stdio.h>
#include<math.h>
int main()
{
int a;
scanf("%d",&a);
if(a%2==0)
{
printf("even");
}
else
{
printf("odd");
}
}
04
#include <stdio.h>
#include<math.h>
int main()
{
char a;
scanf("%c",&a);
if(a%2==0)
{
printf("NO");
}
else
{
printf("YES");
}
}
05
#include <stdio.h>
#include<math.h>
int main()
{
long long x,y;
scanf("%lld %lld",&x,&y);
if(x>y)
{
printf(">");
}
else if(x<y)
{
printf("<");
}
else if(x==y)
{
printf("=");
}
}
06
#include <stdio.h>
#include<math.h>
int main()
{
int x;
scanf("%d",&x);
if((x/10)>0&&(x/10)<10)
{
printf("1");
}
else
{
printf("0");
}
}
07
#include <stdio.h>
#include<math.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if((a>=10)||(b>=20))
{
printf("1");
}
else
{
printf("0");
}
}
08
#include <stdio.h>
#include<math.h>
int main()
{
int a;
scanf("%d",&a);
if((a%3)==0&&(a%5)==0)
{
printf("YES");
}
else
{
printf("NO");
}
}
09
#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<math.h>
int main()
{
int a,b;
int count=0;
scanf("%d %d",&a,&b);
if(a<60)
{
count++;
}
if(b<60)
{
count++;
}
if(count==1)
{
printf("1");
}
else
{
printf("0");
}
}
11
#include <stdio.h>
#include<math.h>
int main()
{
int a[3]={3,5,1};
int date;
scanf("%d",&date);
int i;
int flag=0;
for(i=0;i<3;i++)
{
if(date==a[i])
{
flag=1;
}
}
if(flag==0)
{
printf("YES");
}
else if(flag==1)
{
printf("NO");
}
}
12
#include <stdio.h>
#include<math.h>
int main()
{
int distance;
scanf("%d",&distance);
double bike,walk;
walk=distance/1.2;
bike=50+distance/3.0;
if(bike>walk)
{
printf("Walk");
}
else if(bike<walk)
{
printf("Bike");
}
else if(walk==bike)
{
printf("All");
}
}
13
#include <stdio.h>
#include<math.h>
int main()
{
double x,y;
scanf("%lf",&x);
if(x<5&&x>=0)
{
y=-x+2.5;
}
else if(x<10&&x>=5)
{
y=2-1.5*(x-3)*(x-3);
}
else if(x<20&&x>=10)
{
y=x/2-1.5;
}
printf("%.3f",y);
}
14
#include <stdio.h>
#include<math.h>
int main()
{
int weight,cost,beyond;
char ch;
scanf("%d %c",&weight,&ch);
if(weight<=1000)
{
cost=8;
}
else if(weight>1000)
{
//ceil函数:向上取整,且左右两边为浮点数
beyond=(int)ceil((weight-1000)/500.0);
cost=8+4*beyond;
}
if(ch=='y')
{
cost+=5;
}
else if(ch=='n')
{
}
printf("%d",cost);
}
15
#include <stdio.h>
#include<math.h>
int main()
{
int a,b,c,max;
scanf("%d %d %d",&a,&b,&c);
max=a>b?a:b;
if(c>max)
{
max=c;
}
printf("%d",max);
}
16
#include <stdio.h>
#include<math.h>
int main()
{
int a,b,c;
int flag=0;
scanf("%d %d %d",&a,&b,&c);
if((a<b+c)&&(a>abs(b-c)))
{
if((b<a+c)&&(b>abs(a-c)))
{
if((c<a+b)&&(c>abs(b-a)))
{
flag=1;
}
}
}
if(flag==1)
{
printf("yes");
}
else if(flag==0)
{
printf("no");
}
}
17
#include <stdio.h>
#include<math.h>
int main()
{
int year;
int ch=0;
scanf("%d",&year);
if(year%4==0)
{
ch=1;
if(year%100==0&&year%400!=0)
{
ch=0;
}
if(year%3200==0)
{
ch=0;
}
}
if(ch==0)
{
printf("N");
}
else if(ch==1)
{
printf("Y");
}
}
18
#include <stdio.h>
#include<math.h>
int main()
{
int x,y;
scanf("%d %d",&x,&y);
if(abs(x)<=1&&abs(y)<=1)
{
printf("yes");
}
else
{
printf("no");
}
}
19
#include <stdio.h>
#include<math.h>
int main()
{
int x,y,result;
char ch;
scanf("%d %d %c",&x,&y,&ch);
if(ch=='+')
{
result=x+y;
}
else if(ch=='-')
{
result=x-y;
}
else if(ch=='*')
{
result=x*y;
}
else if(ch=='/')
{
if(y==0)
{
printf("Divided by zero!");
return 0;
}
else
{
result=x/y;
}
}
else
{
printf("Invalid operator!");
return 0;
}
printf("%d",result);
return 0;
}
20
#include <stdio.h>
#include<math.h>
int main()
{
//难点:当deta=0时,x1=x2=-b/(2*a),此时若b=0,则输出值为-0.00000不正确,应当输出相反值,同理deta<0时;
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
#include <stdio.h>
#include<math.h>
int main()
{
//注意当完整的苹果为0时的情况不能为负数
int n,x,y,left;
scanf("%d %d %d",&n,&x,&y);
left=n-ceil(y*1.0/x);
if((n-ceil(y*1.0/x))<=0)
{
printf("0");
}
else
{
printf("%d",left);
}
}