6 条题解

  • 0
    @ 2023-10-22 10:53:05
    #include <iostream>
    using namespace std;
    int main()
    {
        double x;
        cin>>x;
        cout<<(long long)x<<endl;
        return 0;
    }
    
    • 0
      @ 2023-8-20 15:41:58
      #include<iostream>
      #include<cstdio>
      #include<algorithm>
      #include<cstring>
      #include<cmath>
      #include<string>
      #include<cstdlib>
      using namespace std;
      double a;
      int main(){
      	cin>>a;
      	cout<<(long long)a;
      	return 0;
      }
      
      • 0
        @ 2023-3-4 21:59:19

        题目描述

        输入一个单精度浮点数,将其向零舍入到整数。说明:向零舍入的含义是,正数向下舍入,负数向上舍入。

        输入格式

        一个单精度浮点数 xx

        输出格式

        一个整数,即向零舍入到整数的结果。

        • @ 2023-3-4 22:06:29

          这道题首先可以用cmath函数里的“ceil”和“floor”进行计算。但是,需要《整整》两个if进行判断,太《麻烦》了。

          因此我们要一个简单点的方法。我们想到int。它有一个特性,就是会把输入进来的浮点型小数部分删去。我们再分析来看

          ①:2.3。它被输入进int以后,会变成2。 ②:-2.3。它被输入进int以后,会变成-2。 int正好会满足本题条件,所以我们直接把数据输入进int,得到的结果就是我们想要的。

        • @ 2023-3-4 22:11:29

          下面是代码部分

          #include<bits/stdc++.h>
          using namespace std;
          
          long long x;//10^15次方定义long long会吧 
          
          int main(){
          	cin>>x;//输入会吧 
          	cout<<x;//输出会吧 
              return 0;
          }
          
          
      • 0
        @ 2022-5-25 22:48:47

        yeeh

        #include<bits/stdc++.h>
        using namespace std;
        long long q,w,e,r,t,y,u,i,o,p,d,f,g,h,j,k,l,z,x,c,v,b,n,m;
        string s;
        long long a[100000],as[100000],asd[100000];
        char cc;
        double dd;
        int main()
        {
        	cin>>x;
        	cout<<fixed<<setprecision(0)<<x;
            return 0;
        }
        
        • -2
          @ 2022-7-10 18:54:30

          #include <bits/stdc++.h> using namespace std; double x; int main() { cin>>x; if(x>0) { cout<<long(floor(x)); } if(x<0) { cout<<long(ceil(x)); } if(x==0) { cout<<0; } return 0; }

          • -2
            @ 2022-3-28 11:41:44

            先判断正负,然后再使用 <cmath> 库中的 floorceil 函数向下或向上取整即可。

            代码:

            #include <bits/stdc++.h>
            
            using namespace std;
            
            int main() {
                double x;
                cin >> x;
                cout << fixed << setprecision(0) << (x < 0 ? ceil(x) : floor(x)) << endl;
                return 0;
            }
            
            • 1

            信息

            ID
            6828
            时间
            1000ms
            内存
            128MiB
            难度
            1
            标签
            (无)
            递交数
            137
            已通过
            54
            上传者