全部评论 3

  • #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        
        int n, m;
        cin >> n >> m;
        const int total = n * m;
        int* img1 = new int[total];
        for (int i = 0; i < total; ++i) {
            cin >> img1[i];
        }
        int same = 0;
        for (int i = 0; i < total; ++i) {
            int pixel;
            cin >> pixel;
            if (pixel == img1[i]) {
                same++;
            }
        }
        delete[] img1;
        double similarity = (static_cast<double>(same) / total) * 100;
        cout << fixed << setprecision(2) << similarity << endl;
        
        return 0;
    }
    

    2025-08-18 来自 上海

    0
  • #include <iostream>
    #include <vector>
    using namespace std;
    
    vector<int> factorize(int n, int k) {
        vector<int> factors;
        int remaining = n;
        for (int i = 1; i < k; ++i) {
            for (int f = 2; f * f <= remaining; ++f) {
                if (remaining % f == 0 && (remaining / f) >= 1) {
                    factors.push_back(f);
                    remaining /= f;
                    break;
                }
            }
            if (factors.size() < i) {
                if (remaining > 1 && (k - i) == 1) {
                    factors.push_back(remaining);
                    remaining = 1;
                } else {
                    return {};
                }
            }
        }
        if (remaining <= 1) return {};
        factors.push_back(remaining);
        
        return factors;
    }
    
    int main() {
        int n, k;
        cin >> n >> k;
        
        vector<int> result = factorize(n, k);
        
        if (result.empty()) {
            cout << -1 << endl;
        } else {
            for (int i = 0; i < result.size(); ++i) {
                if (i > 0) cout << " ";
                cout << result[i];
            }
            cout << endl;
        }
        
        return 0;
    }
    
    

    2025-08-18 来自 上海

    0
  • #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;
    }
       
    

    2025-08-14 来自 上海

    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;
      

      }

      2025-08-14 来自 上海

      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;
      }
          
      

      2025-08-15 来自 上海

      0

热门讨论