我在提交时遇到运行时错误和 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;
}
我期待的是
答案 0 :(得分:1)
请阅读scanf
man page。这:scanf("%d", T);
应该改为 scanf("%d", &T);
。
其他对 scanf()
的调用也有同样的问题。