Start: Jan, 04, 2017 19:40:00
2016年秋季学期程序设计基础期末考试
End: Jan, 04, 2017 21:40:00
Time elapsed:
Time remaining:

Problem_ID: F
Result: Accepted
Time: 382ms
Memory: 1092kB
Author: 1772780065
In contest: 1084

#include<stdio.h>
#include<string.h>
struct tail{
int a,b;
};
int main(void){
	int T,N,x,y,i,j,k;
	struct tail m[5000],q;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&N);
		memset(m,0,sizeof(m));
		i=0;
		for(x=0;2*x<=N;x++){
			for(y=0;3*y<=N;y++){
				if(2*x+3*y==N){
					m[i].a=x;
					m[i].b=y;
					i++;
				}
			}
		}
		for(j=0;j<i-1;j++){
			for(k=0;k<i-1-j;k++){
				if(m[k].a>m[k+1].a){
					q=m[k];
					m[k]=m[k+1];
					m[k+1]=q;
				}
			}
		}
		if(m[0].a==0&&m[0].b==0)
			printf("WA\n");
		else
			printf("%d %d\n",m[0].a,m[0].b);
	}
	return 0;
}