#13257: 記憶體區段錯誤 請幫忙看看 謝謝


Junhua (Junhua)

學校 : 臺北市立和平高級中學
編號 : 59170
來源 : [1.34.61.75]
最後登入時間 :
2022-06-10 14:14:29
a291. nAnB problem | From: [122.116.41.30] | 發表日期 : 2018-01-19 23:25

#0: 100% RE (SIGSEGV)

記憶體區段錯誤!
Segmentation fault (core dumped)


原始碼如下


#include <iostream>
#include <stdio.h> //scanf printf
#include <stdlib.h>
#include <string.h> //string
#include <math.h>
using namespace std;

int main(){
int ans[5];
int guess[5];
int A=0,B=0;
long int times;

int a[5],z=0,y;

while( cin>>ans[0] ){

for(int a=1;a<4;a++)cin>>ans[a];
cin>>times;
for(long int i=0;i<times;i++){

for(int b=0;b<4;b++)cin>>guess[b];

for(int j=0;j<=3;j++){

for(int k=0;k<=3;k++){
if(ans[j]==guess[k] && j==k ){
A++;
a[z]=ans[j]; z++;
}
else if(ans[j]==guess[k]) {
for(y=0;y<=3;y++){
if(ans[j]==guess[k] && guess[k]==a[y])break;
} if(ans[j]==guess[k] && y==4)B++;
}
}

}

printf("%dA%dB\n",A,B);
A=0; B=0; y=0;//歸零
}
}
}
 
#13259: Re:記憶體區段錯誤 請幫忙看看 謝謝


anandrewboy70900 (ShowTsai)

學校 : 國立中央大學
編號 : 27736
來源 : [203.204.218.144]
最後登入時間 :
2024-02-07 22:53:10
a291. nAnB problem | From: [124.12.88.166] | 發表日期 : 2018-01-20 12:31

z沒歸零

 




 
#13260: Re:記憶體區段錯誤 請幫忙看看 謝謝


anandrewboy70900 (ShowTsai)

學校 : 國立中央大學
編號 : 27736
來源 : [203.204.218.144]
最後登入時間 :
2024-02-07 22:53:10
a291. nAnB problem | From: [124.12.88.166] | 發表日期 : 2018-01-20 12:32

z沒歸零

 



然後你的算法有點問題 再想想吧




 
ZeroJudge Forum