只有12过了,求助大佬

P1085 [NOIP2004 普及组] 不高兴的津津

@[Haidde](/user/1215070) 最后输出的应该是maxi+1,不是i+1
by cancan1030 @ 2024-02-18 11:53:43


@[Haidde](/user/1215070) 下次写完代码可以拿题目给的样例自测一下,能很大程度上避免这种小错误
by cancan1030 @ 2024-02-18 11:55:19


@[cancan1030](/user/1020332) 好的好的,谢谢大佬
by Haidde @ 2024-02-18 11:56:35


@[Haidde](/user/1215070) 这是我的代码: ```cpp #include<bits/stdc++.h> using namespace std; const int N=10; int a[N]; int main(){ for(int i=1;i<=7;i++){ int x,y; cin>>x>>y; a[i]=x+y; } if(*max_element(a+1,a+8)<8){ cout<<0; return 0; } else{ int maxn=0,maxi=0; for(int i=1;i<=7;i++){ if(a[i]>maxn){ maxn=a[i]; maxi=i; } } cout<<maxi; } return 0; } ```
by cancan1030 @ 2024-02-18 12:00:24


@[Haidde](/user/1215070) 不客气
by cancan1030 @ 2024-02-18 12:01:02


@[Haidde](/user/1215070) ```c #include <iostream> #include <vector> using namespace std; int main() { vector<int> t1(7); vector<int> t2(7); for (int i = 0; i < 7; ++i) { cin >> t1[i] >> t2[i]; } vector<int> t(7); t[0] = t1[0] + t2[0] - 8; for(int i = 1; i < 7; ++i) { int x1 = t1[i-1] + t2[i-1] - 8; int x2 = t1[i] + t2[i] - 8; if (x2 > 0) { if (x1 > 0) t[i] = x1 + x2; else t[i] = x2; } else { if (x1 > 0) t[i] = x1; else t[i] = 0; } } int res = -1; int index = 0; for (int i = 0; i < 7; ++i) { if (t[i] > res) { res = t[i]; index = i; } } cout << index+1; } ``` 为什么我的不对,测试只过了半数。而且样例2有问题啊。 输入: 4 4 2 2 0 4 5 4 6 3 0 0 0 5 输出:4 应该输出5而不是4啊。
by Feifly @ 2024-02-20 19:45:46


|