CSP試題—— 風險人群篩查

w巧克力聖代發表於2020-10-07

CSP試題—— 風險人群篩查

2020.10.07

By ljm

在這裡插入圖片描述

C語言滿分答案:

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n,k,t,x1,y1,x2,y2,x,y,i,j,count=0,pass=0,stay=0,flag1=0,flag2=0;
	scanf("%d %d %d %d %d %d %d",&n,&k,&t,&x1,&y1,&x2,&y2);
	for(i=0;i<n;i++){
		for(j=0;j<t;j++){
			scanf("%d %d",&x,&y);
			if((x1<=x)&&(x<=x2)&&(y1<=y)&&(y<=y2)){
				count++;
				if(count==k){
					count=0;
					flag1=1;
				}
				flag2=1;
			}
			else{
				count=0;
				continue;
			}
		}
		if(flag1==1){
			stay++;
			flag1=0;
		}
		if(flag2==1){
			pass++;
			flag2=0;
		}
	}
	printf("%d\n%d",pass,stay);
	return 0;
}

相關文章