NOI / 1.4编程基础之逻辑表达式与条件分支(下)来啦!!

本人openjudge账号,欢迎私信讨论@@。。

好了,废话不多说,下面是题解::(ya

11.#include<bits/stdc++.h>using namespace std;int main (){

int day;

cin>>day;

if(day==2){

cout<<"YES";

}

else if(day==4){

cout<<"YES";

}

else if(day==6){

cout<<"YES";

}

else if(day==7){

cout<<"YES";

}

else if(day==1){

cout<<"NO";

}

else if(day==3){

cout<<"NO";

}

else if(day==5){

cout<<"NO";

}

return 0;}

12.#include<bits/stdc++.h>using namespace std;int main(){

double a,b,n;

scanf("%lf",&n);

a=n/3.0+27+23;b=n/1.2;

if(a<b) cout<<"Bike";

else if(a==b) cout<<"All";

else if(a>b) cout<<"Walk";

return 0;}

13.#include <bits/stdc++.h>using namespace std;int main(){

double x,y;

cin>>x;

if(x>0&&x<5) y=-x+2.5;

else if(x>=5&&x<10) y=2-1.5(x-3)(x-3);

else if(x>=10&&x<20) y=x/2-1.5;

printf("%.3lf",y);

   return 0;}

14.#include<bits/stdc++.h>using namespace std;int main(){

int k,s=8;char w;

cin>>k>>w;

if(k>1000)

if((k-1000)%500!=0) s+=((k-1000)/500+1)*4;

  else s+=(k-1000)/500*4;

  if(w=="y") s+=5;

  printf("%d/n",s);

return 0;}

15.#include <stdio.h>

int main(void){

    int a, b, c;

    scanf("%d%d%d", &a, &b, &c);

    

    if (a > b) {

        int temp = a;

        a = b;

        b = temp;

    }

    

    if (b > c) {

        int temp = b;

        b = c;

        c = temp;

    }

    

    printf("%d\n", c); /* 经过两轮交换,c一定是最大的 */

    return 0;}

16.#include <stdio.h>

int main(void){

    int a, b, c;

    scanf("%d%d%d", &a, &b, &c);

    if ((a + b > c) && (a - b < c))

        printf("yes\n");

    else

        printf("no\n");

    return 0;}

17.#include<bits/stdc++.h>using namespace std;int main (){

int year; 

cin>>year;

if(year%4==0&&year%100!=0||year%400==0){

cout<<"Y";

}

else{

cout<<"N";

}

return 0;}

18.#include<stdio.h>

int main(void){

    int x, y;

    scanf("%d%d", &x, &y);

    if(-1 <= x && x <= 1 && -1 <= y && y <= 1)

        printf("yes");

    else

        printf("no");

    

    return 0;}

19.#include <stdio.h>

int main(void){

    int a, b, c;

    char ch;

    scanf("%d%d %c", &a, &b, &ch);/* 在%c前加一个空格,不然程序会出问题 */

    switch (ch)

    {

        case '+':

        {

            c = a + b;

            printf("%d\n", c);

            break;

        }

        case '-':

        {

            c = a - b;

            printf("%d\n", c);

            break;

        }

        case '*':

        {

            c = a * b;

            printf("%d\n", c);

            break;

        }

        case '/':

        {

            if (b == 0) {

                printf("Divided by zero!\n");

            } else {

                c = a / b;

                printf("%d\n", c);

            }

            break;

        }

        default:

        {

            printf("Invalid operator!\n");

            break;

        }

    }

    return 0;}

20.#include<stdio.h>#include<math.h>

int main(void){

    float a, b, c;

    scanf("%f%f%f", &a, &b, &c);

    if(b * b == 4 * a * c)

    {

        if(b == 0)

            printf("x1=x2=%.5f\n", b / (2 * a));

        else

            printf("x1=x2=%.5f\n", (-b) / (2 * a));

    }

    else if(b * b > 4 * a * c)

        printf("x1=%.5f;x2=%.5f\n", (-b + sqrtf((b * b - 4 * a *c))) / (2 * a), (-b - sqrtf(b * b - 4 * a * c)) / (2 * a));

    else

    {

        if(b == 0)

            printf("x1=%.5f+%.5fi;x2=%.5f-%.5fi\n", b / (2 * a), sqrtf(4 * a * c - b * b) / (2 * a), b / (2 * a), sqrtf(4 * a * c - b * b) / (2 * a));

        else

            printf("x1=%.5f+%.5fi;x2=%.5f-%.5fi\n", -b / (2 * a), sqrtf(4 * a * c - b * b) / (2 * a), -b / (2 * a), sqrtf(4 * a * c - b * b) / (2 * a));

    }

    return 0;}

21.#include <stdio.h>

int main(void){

    int n, x, y;

    scanf("%d%d%d", &n, &x, &y);

    

    if (y >= n * x) /* 苹果吃完了 */

        printf("0\n");

    else if (y % x == 0) /* 苹果没有吃完 */

        printf("%d\n", n - y / x);

    else

        printf("%d\n", n - y / x - 1);

    return 0;}

这都是人家姐姐辛辛苦苦,呕心沥血写的题,

你们不给个小爱心小心脏不会痛吗亲???

一键三连,转发+收藏!!

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值