#38106: c 基礎寫法


q0908309831@gmail.com (浪人飄飄)

學校 : 不指定學校
編號 : 234983
來源 : [140.118.154.127]
最後登入時間 :
2023-11-15 14:44:05
a291. nAnB problem | From: [140.118.74.187] | 發表日期 : 2023-10-26 16:22

#include <stdio.h>
 
int main() {
 
int pwd_con[4] = { 0 };
 
while (scanf("%d%d%d%d", &pwd_con[0], &pwd_con[1], &pwd_con[2], &pwd_con[3]) != EOF) {
 
 
 
char c = getchar(); //讀取回車鍵
int times = 0;
int info[4] = { 0 };
scanf("%d", &times);
 
for (int j = 0; j < times; j++) {
 
int pwd[4] = { 0 };//這樣就可以修改
for (int i = 0; i < 4; i++) pwd[i] = pwd_con[i];
 
int info[4] = { 0 };
int N = 10, A = 0, B = 0;
scanf("%d%d%d%d", &info[0], &info[1], &info[2], &info[3]);
c = getchar(); //讀取回車鍵
//輸入讀取完畢
 
for (int i = 0; i < 4; i++) { //位置同值也同
if (info[i] == pwd[i]) {
A++;
info[i] = N;
N++;
pwd[i] = N;
N++;
}
}
for (int i = 0; i < 4; i++) { //位置同值也同
for (int x = 0; x < 4; x++) {
if (info[x] == pwd[i]) {
B++;
info[x] = N;
N++;
pwd[i] = N;
N++;
}
}
}
printf("%dA%dB\n", A, B);
 
 
}
 
 
}
 
return 0;
}
看了許多人的,總感覺自己寫的沒有很好,有興趣的可以看一下,核心就是把裡面值替換掉,就不會有重複情況
 
ZeroJudge Forum