变强了,也秃了 2022-07-22 15:23 采纳率: 66.7%
浏览 28
已结题

OJ-涂气球,这是我自己想的一个办法,没有用差分知识,中间那一段不知道为什么不输出

中间那一段输出直接被跳过,不知道什么原因

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    int N;
    int s[1000];
    while (cin >> N && N != 0)
    {
        int n = N;
        int a, b;
        memset(s, 0, sizeof(s));
        while (n--);
        {
            cin >> a >> b;
            if (a == b)
                s[a]++;
            else
                for (int i = 1; i <= b - a; i++)
                    s[i]++;
        }
        for (int j = 1; j <= n; j++)
        {
            cout << s[j];
            cout << " ";
        }
        cout << endl;
    }
    
    return 0;
}
  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-07-22 15:28
    关注

    while (n--);
    这个后面分号去掉
    另外while结束后,n就变为负数了,所以23行的for循环自然就跳过去啦

    #include <iostream>
    #include <string.h>
    using namespace std;
     
    int main()
    {
        int N;
        int s[1000];
        while (cin >> N && N != 0)
        {
            int n = N;
            int a, b;
            memset(s, 0, sizeof(s));
            while (n--)
            {
                cin >> a >> b;
                if (a == b)
                    s[a]++;
                else
                    for (int i = 1; i <= b - a; i++)
                        s[i]++;
            }
            for (int j = 1; j <= N; j++)
            {
                cout << s[j];
                cout << " ";
            }
            cout << endl;
        }
        
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 7月30日
  • 已采纳回答 7月22日
  • 修改了问题 7月22日
  • 创建了问题 7月22日

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗