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

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