1345 Legion training camp

Source: Internet
Author: User
Description

Mr. S is the commander of the Missile Corps. He has a group of soldiers capable of missile technology. Each soldier has a technical level score and is divided into one group of troops based on the technical level score. Several regiments form a temporary missile force. Today he is interested and wants to merge the two missile troops. However, he hopes that all the technology groups will be arranged in order to form a team from high to low, of course, after the same technology group is merged, the two teams are merged into one team.

Now he is too tired, because he has been practicing missile technology for too long yesterday ...... So I hope you can help him merge the team ......

The rules for providing army intelligence information are as follows:

For any group of two troops, their technical score is di (0 <= di <= 2000), and their team has AI (1 <= AI <= 10000) personnel.

For a single army, the information is

A1 d1

A2 D2

...

An DN

0 0

0 0 is used as the end mark. Two troops are provided.

I hope that you will return the information of the merged troops and deliver the information from low to high according to missile technology.

Input

The first line of input data is T, indicating that T groups of data exist;

The following T blocks contain information about two troops. The specific rules are described.

Output

For each group of data, information about the combined troops is output, sorted in ascending order by technical score.

 

Just sort questions by simulation.

#include <stdio.h>main(){int number,te;    double a1[2001],a2[2001];   double b1[2001],b2[2001];   double c1[4002],c2[4002];double temp1,temp2;int up1,up2,up3;int i,j;scanf("%d",&number);for(te=1;te<=number;te++){scanf("%lf %lf",&temp1,&temp2);up1=0;up2=0;while(!(temp1==0&&temp2==0)){a1[up1]=temp1;a2[up1]=temp2;up1++;scanf("%lf %lf",&temp1,&temp2);}       scanf("%lf %lf",&temp1,&temp2);    while(!(temp1==0&&temp2==0)){b1[up2]=temp1;b2[up2]=temp2;up2++;          scanf("%lf %lf",&temp1,&temp2);}up3=0;       for(i=0;i<up1;i++)   for(j=0;j<up2;j++)   {   if(a2[i]==b2[j]&&a1[i]!=-1)   { c1[up3]=a1[i]+b1[j];     c2[up3]=a2[i]; up3++; a1[i]=-1; b1[j]=-1;   }   }      for(i=0;i<up1;i++)  if(a1[i]!=-1)  {   c1[up3]=a1[i];      c2[up3]=a2[i];       up3++;  }for(j=0;j<up2;j++)if(b1[j]!=-1){c1[up3]=b1[j];c2[up3]=b2[j];up3++;}for(i=0;i<up3;i++)for(j=i+1;j<up3;j++){if(c2[i]>c2[j]){temp1=c2[j];temp2=c1[j];c2[j]=c2[i];c1[j]=c1[i];c2[i]=temp1;c1[i]=temp2;}}for(i=0;i<up3;i++)printf("%.0lf %.0lf\n",c1[i],c2[i]);}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.