全部评论 1

  • #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main() {
        // 定义目标数值数组
        double targets[] = {1.1, 2.2, 3.3, 4.4, 5.5};
        // 读取输入的实数
        double y;
        cin >> y;
        
        // 检查输入的数属于哪个目标值的附近范围
        for (double x : targets) {
            if (y >= x - 0.4 && y <= x + 0.4) {
                // 找到匹配的目标值,输出并结束程序
                cout << fixed << setprecision(1) << x << endl;
                return 0;
            }
        }
        
        // 题目保证输入一定在某个数字附近,所以这里理论上不会执行
        return 0;
    }
       
    

    2天前 来自 上海

    0
    • #include <iostream>
      #include <iomanip>

      int main() {
      int electricity;
      std::cin >> electricity;

      double cost = 0;
      
      if (electricity <= 150) {
          cost = electricity * 0.4463;
      } else if (electricity <= 450) {
          cost = 150 * 0.4463 + (electricity - 150) * 0.4663;
      } else {
          cost = 150 * 0.4463 + 300 * 0.4663 + (electricity - 450) * 0.5663;
      }
      
      // 设置输出精度为11位小数
      printf("%.1lf",cost);
      return 0;
      

      }

      2天前 来自 上海

      0
    • #include <iostream>
      using namespace std;
      
      int main() {
          int n;
          cin >> n;  // 读取同学数量
          
          int height;
          cin >> height;  // 先读取第一个身高
          
          // 初始化最大值和最小值为第一个身高
          int max_h = height;
          int min_h = height;
          
          int i = 1;
          // 使用while循环读取剩余的n-1个身高
          while (i < n) {
              cin >> height;
              
              // 更新最大值
              if (height > max_h) {
                  max_h = height;
              }
              
              // 更新最小值
              if (height < min_h) {
                  min_h = height;
              }
              
              i++;
          }
          
          // 计算差值
          int diff = max_h - min_h;
          
          // 输出结果
          cout << max_h << " " << min_h << " " << diff << endl;
          
          return 0;
      }
          
      

      昨天 来自 上海

      0

热门讨论