CSP考試 2014年12月第1題 門禁系統 C語言實現
阿新 • • 發佈:2019-01-06
#include <stdio.h> /* struct hello { int hao; int shu; };*/ int main() { /* int NUM=5; int a[NUM]; int b[NUM]; //struct hello b[NUM]; //struct hello b[0]={0,0}; //struct hello b[1]={0,0}; //struct hello b[2]={0,0}; //struct hello b[3]={0,0}; //struct hello b[4]={0,0}; a[0]=1; a[1]=2; a[2]=1; a[3]=1; a[4]=3; int i;*/ int NUM; scanf("%d",&NUM); int a[NUM]; int i; for(i=0;i<NUM;i++) { scanf("%d",&a[i]); } int b[NUM]; int j; for(i=0;i<NUM;i++) { b[i]=0; } for(i=0;i<NUM;i++) { for(j=0;j<=i;j++) { if(a[i]==a[j]) { b[i]++; //printf("i=%d j=%d b[%d]=%d\n",i,j,i,b[i]); } } } for(i=0;i<NUM;i++) { printf("%d ",b[i]); //printf("i=%d b[%d]=%d\n",i,i,b[i]); } return 0; }