跳到正文

个人记录

【四月份 -- 基础语法组】-- T1-- 取整(integer.cpp)

zhangyuqiTAT约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年4月12日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v1当前

题解: https://b1bznc26af6.feishu.cn/file/BMmWbumodokMN6x3NIEcvrelnib?from=from_copylink

网址:

https://cspjs.online/contest/680/problem/1

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("integer.in","r",stdin);
    freopen("integer.out","w",stdout);
    long long a,b,q;
    cin>>a>>b>>q;
    if(q==1)cout<<a/b;
    else if(q==2){
        if(a/b>=0)printf("%lld",a/b+(a%b==0?0:1));
        else cout<<a/b;
    }
    else if(q==3){
        if(a/b<0)printf("%lld",a/b+(a%b==0?0:-1));
        else cout<<a/b;
    }
    else if(q==4){
        cout<<fixed<<setprecision(0)<<a/b;
    }
    return 0;
}
原文