YY编程题输入多行,但没具体说输入几行,怎么结束输入?

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

int main() {

    int a, b, c;
    map<int, int> m;
    map<int, int> m_f;
    int i;
    while ( scanf_s("%d %d %d", &a,&b,&c) != EOF) {//// 请问:while循环怎么退出????
        m[a] = c;
        m[b] = c;
        m_f[a] = 1;
    }

    auto it2 = --m.end();
    ++m.end();

    for (auto it = m.begin(); it != it2;) {
        int a = it->first;
        int b = it->second;

        auto itTmp = ++it;
        int key = itTmp->first;
        if (m_f.count(key) > 0) {//key为范围尾端
            cout << a << ' ' << ' ' << key - 1 << ' ' << b << endl;
        }
        else {
            if (m_f.count(a) <= 0 && m_f.count(key) > 0) {
                a += 1;
                key -= 1;
            }
            cout << a << ' ' << key << ' ' << m[key] << ' ' << b << endl;
        }
    }


    return 0;
}
#C++工程师#
全部评论
读入到文件尾,代码这样写是OK的,你手动操作的情况下可以按ctrl+z再按回车停止输入
点赞 回复
分享
发布于 2017-09-17 21:19

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务