还有更加简便的算法吗,求助大佬们!!

B2016 浮点数向零舍入

2_202240210224 @ 2023-06-07 19:17:52

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

int main(){
    double a;
    cin>>a;
    long long n;
    n=a;
    if(n<0){
        printf("%ld",n);
    }
    else{
        printf("%ld",n);
    }
    return 0;
}

by __My0217__ @ 2023-06-07 19:20:42

#include<iostream>
using namespace std;

int main()
{
    double x;
    cin>>x;
    cout<<(long long)x;
    return 0;
}

用这个过了


by rechenz @ 2023-06-07 20:11:34

@2_202240210224 应该是最简单的了吧

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

int main(){
    long long n;
    cin>>n;
    cout<<n;
    return 0;
}

by 2_202240210224 @ 2023-06-07 21:41:22

@rechenz 谢谢啦


by 2_202240210224 @ 2023-06-07 21:41:58

@My0217 谢谢啦


by Ryanwu @ 2023-07-02 17:12:31

#include <iostream>
using namespace std;
int main() {
    double n;
    cin>>n;
    cout<<(int)n<<endl;
    return 0;
}

|