人口普查解答过程中遇到的问题

结果有一个段错误,请大家看看有没有什么漏洞,谢谢!

img

img


```c++

#include <iostream>
#include <vector>
using namespace std;

typedef struct {
    string name;
    int year;
    int month;
    int day;
} Peo;

int main() {
    int n;
    string name, date;
    vector<Peo> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> name >> date;
        // 解析日期
        int pos1 = date.find('/');
        int pos2 = date.find('/', pos1 + 1);
        int year = stoi(date.substr(0, pos1));
        int month = stoi(date.substr(pos1 + 1, pos2 - pos1 - 1));
        int day = stoi(date.substr(pos2 + 1));

        if (year > 2014 || (2014 - year) > 200) {
            continue;
        } else if (year == 2014) {
            if(month>9){
                continue;
            }else if(month==9&&day>6){
                continue;
            }
        }else if((2014 - year) == 200){
            if(month<9)continue;
            else if(month==9&&day<6)continue;
        }
        Peo p;
        p.name = name;
        p.year = year;
        p.month = month;
        p.day = day;
        s.push_back(p);
    }
    Peo young = s[0];
    Peo old = s[0];
    for (int i = 1; i < s.size(); i++) {
        if (s[i].year > young.year ||
            (s[i].year == young.year && s[i].month > young.month) ||
            (s[i].year == young.year && s[i].month == young.month && s[i].day > young.day))
        {
            young = s[i];
        }
        if (s[i].year < old.year ||
            (s[i].year == old.year && s[i].month < old.month) ||
            (s[i].year == old.year && s[i].month == old.month && s[i].day < old.day))
        {
            old = s[i];
        }
    }

    cout << s.size() << " " << old.name << " " << young.name;
    return 0;
}

```

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^