标签:nal int stream com main out printf i++ 代码
错误答案1:
#include<iostream> using namespace std; const int maxn=100000; int a[maxn]={0}; int main(){ int n,id,sco,k,j; cin>>n; for(int i=0;i<n;i++){ a[id]+=sco; } for(id=1;id<n;id++) { if(a[id]<a[id+1]){ j=(id+1); k=a[id+1]; } else{ j=id; k=a[id];
} } }
正确代码1: #include<cstdio> const int MAx=100010; int main() { int count[MAx]={0}; int n,ID,score; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&ID,&score); count[ID]+=score; } //测试 int max=-1; int k=1; for(int i=1;i<=n;i++) { if(count[i]>=max) { max=count[i]; k=i; } } printf("%d %d",k,max); return 0; }
正确代码2:
#include<iostream> using namespace std; const int maxn=100000; int a[maxn]={0}; int main(){ int n,id,sco,k,j; cin>>n; for(int i=0;i<n;i++){ cin>>id>>sco; a[id]+=sco; } k=-1;j=-1; for(int i=1;i<=n;i++) //最好吧i<=n改成i<=maxn,可应对编号不连续的情况。 { if(a[i]>j) { j=a[i]; k=i; } } cout<<k<<" "<<j; return 0; }
链接:https://www.nowcoder.com/questionTerminal/8ec60eb06fad461eb82ff30562eedc31 来源:牛客网 #include<stdio.h> int main() { int a[100000]={0}; int n,x,y; int max=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d %d",&x,&y); a[x]+=y; if(a[x]>a[max]) max=x; } printf("%d %d",max,a[max]); return 0; }
标签:nal int stream com main out printf i++ 代码
原文地址:https://www.cnblogs.com/leamant/p/13286266.html