80分求助

B2046 骑车与走路

Lost_Castle @ 2023-08-27 15:09:05

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    if(50>=a){
        cout<<"Walk";
    }else if(a/6/5>(a-50)/3){
        cout<<"walk";
    }else if(a/6/5==(a-50)/3){
        cout<<"All";
    }else{
        cout<<"Bike";
    }
    return 0;
}

by HASPID @ 2023-09-08 11:14:57

要求餘數,有就加一,沒就不加


by HASPID @ 2023-09-08 11:16:48

#include<iostream>
using namespace std;
int main(){
    int a,b=12,c=30,d,e;
    cin>>a;
    a=a*10;
    if(a%b==0)d=a/b;
    else if(a%b!=0)d=a/b+1;
    if(a%c==0)e=a/c+50;
    else if(a%c!=0)e=a/c+1+50;
    if(d<e)cout<<"Walk";
    else if(d==e)cout<<"All";
    else if(d>e)cout<<"Bike";
}

by _Amy @ 2023-09-09 13:58:01

@IMPOSTORrrrrrr 跟余数有关系?

#include <bits/stdc++.h>
using namespace std;

int main(){

    int k;
    int tbike,twalk;
    cin>>k;
    tbike = (27+23) + (k / 3 );
    twalk = k / 1.2 ;
    if(tbike>twalk){
        cout<<"Walk";
    }

    if(tbike<twalk){
            cout<<"Bike";
        }

    if(tbike==twalk){
            cout<<"All";
        }

    return 0;   

}

我的代码


by HASPID @ 2023-09-09 17:04:18

@_Amy 整數嗎,向下取整,加一,用公式的當我沒説


by tongtong2012 @ 2023-10-12 20:12:58

干吗这么麻烦,直接double,不是更简单了吗?

#include<bits/stdc++.h>
using namespace std;
int main(){
    double Bike=50,Walk=0,x;
    cin>>x;
    Walk+=x/1.2;
    Bike+=x/3;
    if(Walk<Bike)cout<<"Walk";
    else if(Walk>Bike)cout<<"Bike";
    else cout<<"All";
    return 0;
}

求关!abs(100%)回关


by yangchenran @ 2023-12-13 13:27:41

@Scaramouche___fly 我一开始也是这个问题,建议你把a改成double。


|