c++ - a.exe 不会在 2 行后接受输入
问题描述
我对 c++ 有点陌生,想用它来解决问题,但我发现输入不会超过 2 行。有人可以帮我吗?输入格式在这里http://www.usaco.org/index.php?page=viewproblem2&cpid=568。它应该读取多行输入来解决问题。
例如,请参阅下面的输入
输入示例:
3 3
40 75
50 35
10 45
40 76
20 30
40 40
当我将其粘贴到控制台中,期望代码给出答案时,控制台在第二行的 75 之后切断。我希望将整个内容输入到代码中,但只输入前两行。
#include <bits/stdc++.h>
using namespace std;
int cow[100];
int limit[100];
int N, M;
int currMile = 0;
int main() {
cin >> N >> M;
for(int x = 0; x < N; x++) {
int len, speed;
cin >> len >> speed;
for(int x = currMile; x < len + currMile; x++) {
limit[x] = speed;
currMile += 1;
}
}
currMile = 0;
for(int j = 0; j < M; j++) {
int len, speed;
cin >> len >> speed;
for(int i = currMile; i < len + currMile; i++) {
cow[i] = speed;
currMile += 1;
}
}
int max = 0;
for(int h = 0; h < 100; h++) {
if(cow[h] - limit[h] > max) {
max = cow[h] - limit[h];
}
}
cout << max;
return 0;
}
解决方案
不知道你在问什么。你想让你的程序循环吗?
while (cin >> N >> M)
{
// rest of your code
}
推荐阅读
- python - 可以同时做更多的动作吗?
- emacs - Emacs eww - 如何切换到在文本字段中输入?
- javascript - momentjs businessDiff() 如何工作?
- azure - nifi 处理器 ListAzureBlobStorage 不区分文件和文件夹
- apache-spark - PySpark 在列值上并行拆分 DataFame
- iis-6 - IIS 6 管理用户页面
- javascript - 如何在字符串的开头和结尾匹配相同的字符
- php - 我如何解决在 laradock selenium 中连接失败和连接被拒绝的问题
- c++ - 矩阵c ++的对角线元素之和
- excel - VB Excel (VSTO) - 以基于数据类型的列格式将 DataTable 导出到 Excel