【洛谷】P1106 删数问题
发布日期:2021-05-12 19:55:21 浏览次数:17 分类:精选文章

本文共 2628 字,大约阅读时间需要 8 分钟。

C++���������������������

������������������������������������������������������������������������������������������������������������������������


������������

���������������������������������

  • ���������������

    #include 
    #include
    #include
    #include

    ���������������������������C++������I/O������������

  • ������������

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    ������������������������������������������������������������������

  • ���������������

    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    ���������������������������������������


  • ���������������������

    ���������������������������������������������n������������������������

  • ������������������
  • n += "0";

    ���������������������������������0������������

    1. ������������
    2. while (k--) {
      for (int i = 0; i < n.size() - 1; i++) {
      if (n[i] > n[i+1]) {
      n.erase(i, 1); // ���������
      break;
      }
      }
      }
      • ������������������������������������������������������������������������������������������
      • ���������������������������������������������
      1. ���������������
      2. int check = 0, flag = 0;
        while (n[check] == '0') check++;
        • ���������������������������������0������������������
        1. ������������
        2. for (int i = check; i < n.size() - 1; i++) {
          cout << n[i];
          flag = 1;
          }
          • ���������������������������������������������������0������

          ������������

        3. ������������

          ������������������������������������������������

        4. ������������

          ���������������������������������������������������������������������

        5. ������������

          ������������������������������������������������������������������������������������


        6. ������������������

          #include 
          #include
          #include
          #include
          int main() {
          std::ios::sync_with_stdio(false);
          std::cin.tie(0);
          std::cout.tie(0);
          std::string n;
          int k;
          std::cin >> n >> k;
          n += "0";
          while (k--) {
          for (int i = 0; i < n.size() - 1; i++) {
          if (n[i] > n[i+1]) {
          n.erase(i, 1);
          break;
          }
          }
          }
          int check = 0, flag = 0;
          while (n[check] == '0') check++;
          for (int i = check; i < n.size(); ++i) {
          if (n[i] != '0') {
          std::cout << n[i];
          flag = 1;
          break;
          }
          }
          if (!flag) {
          std::cout << "0";
          }
          }

          ������

          ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:【洛谷】P4995 跳跳!
    下一篇:【洛谷】P1990 覆盖墙壁

    发表评论

    最新留言

    表示我来过!
    [***.240.166.169]2025年04月05日 15时33分28秒