【发布时间】:2021-09-26 12:39:38
【问题描述】:
我在提交时遇到运行时错误和 WA,我的代码非常基本,因此您可以查看它
问题:https://www.codechef.com/problems/PLAYFIT
解决方案(获取“SIGSEGV”):
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
//taking test cases
int T=0;
scanf("%d", T);
while(T--){
int N=0, diff=0, maxDif=-1, gi=0, gj=0;
//taking N
scanf("%d", N);
//taking match 1 goals
scanf("%d", gi);
for(int i=1;i<N;i++){
//taking consecutuve goals in match
scanf("%d", gj);
//calc diff
diff = gj - gi;
if (diff > maxDif){
maxDif = diff;
}
gi = gj;
}
//output
if(maxDif >0){
//cout<<maxDif<<endl;
printf("%d \n", maxDif);
}else{
//cout<<"UNFIT"<<endl;
printf("UNFIT \n");
}
}
return 0;
}
我期待的是
- 我收到运行时错误的解决方案和解释/
- 解决此特定问题的更好方法。
【问题讨论】:
标签: c segmentation-fault