北邮OJ 141 虚数

北邮OJ 虚数

在这里插入图片描述在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
typedef struct fushu{
	int x;		//实部 
	int y;		//虚部 
	int c;		//模 
}Fushu;
Fushu a[101];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int count=0;
		for(int j=0;j<101;j++){
			a[j].x=0;
			a[j].y=0;
			a[j].c=0;
		}			//初始化
		int n;
		int i=0;
		scanf("%d",&n);
		while(n--){
			char s[20];
			cin>>s;
			if(!strcmp(s,"Insert")){
				scanf("%d+i%d",&a[i].x,&a[i].y);
				count++;
				a[i].c=a[i].x*a[i].x+a[i].y*a[i].y; 
				i++;
				printf("Size: %d\n",count);
			}
			if(!strcmp(s,"Pop")){
				if(count==0)
					printf("Empty!\n");
				else{
					int max=0;
					for(int j=1;j<101;j++){
						if(a[max].c<a[j].c)
							max=j;
					}
						printf("%d+i%d\n",a[max].x,a[max].y);
						a[max].x=a[max].y=a[max].c=0;
						count--;
					if(count>0) 
						printf("Size: %d\n",count);
					else
						printf("Empty!\n"); 
				}
			}
		}
	}
}

猜你喜欢

转载自blog.csdn.net/bingkuoluo_/article/details/88808467