#45574: 有土地公加持的 cpp 解( Very Easy)


1121232@stu.wghs.tp.edu.tw (Ian911436)

學校 : 臺北市私立薇閣高級中學
編號 : 258883
來源 : [60.248.154.143]
最後登入時間 :
2025-06-20 09:40:35

#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a, b;
cin >> a;
while(cin >> b){
    if(b==0){ //判斷結束時間
        break;
    }
    if(b % a == 0){
        cout << b/a << endl;
    }
    else{ //用floor向下取整
        cout << (a*(floor(b/a)+1))-b << endl;
    }
}
    return 0;
}

 

#46286: Re: 有土地公加持的 cpp 解( Very Easy)


1121226@stu.wghs.tp.edu.tw (Arthur✨EC)

學校 : 臺北市私立薇閣高級中學
編號 : 252772
來源 : [60.248.154.139]
最後登入時間 :
2025-08-21 12:59:45

// 這部簡短很多
#include <bits/stdc++.h>
using namespace std; int main() { int n,t; cin>>n; while(cin>>t&&t!=0){ cout<<(t%n==0?t/n:n-t%n)<<endl; } return 0; }