記憶體區段錯誤! 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;//歸零
}
}
}