# QM6P5B editorial

Practice

Contest

Author: Chandan Boruah

Tester: Chandan Boruah

Editorialist: Chandan Boruah

EASY

### PREREQUISITES:

Sorting (bubble).

### PROBLEM:

Given few teams with scores and groups. Find what happens to the group winners when two teams swap groups.

### QUICK EXPLANATION:

Swap the two teams in the groups with the scores and then sort the teams in the groups.

### EXPLANATION:

Swap the two teams in the groups along with their scores. Do a bubble sort on the groups, swap positions if scores are in ascending and only if the groups of the teams are same. Since same name groups appear contigously the groups won’t mix and everything would be sorted. Then print the winners of each group.

### AUTHOR’S SOLUTION IN C#:

``````using System;
class some
{
public static void Main()
{
for(int t=0;t<n;t++)
{
int a=int.Parse(ss);
int b=int.Parse(ss);
string[]names=new string[a*b];
string[]teams=new string[a*b];
int[]scores=new int[a*b];
for(int i=0;i<names.Length;i++)
{
names[i]=ss;
teams[i]=ss;
scores[i]=int.Parse(ss);
}
string aa=ss;
string bb=ss;
int indA=Array.IndexOf(names,aa);
int indB=Array.IndexOf(names,bb);
names[indA]=bb;
names[indB]=aa;
int temp=scores[indA];
scores[indA]=scores[indB];
scores[indB]=temp;
for(int i=0;i<scores.Length;i++)
{
for(int j=0;j<scores.Length-1;j++)
{
if(scores[j]<scores[j+1] && teams[j]==teams[j+1])
{
int tt=scores[j];
scores[j]=scores[j+1];
scores[j+1]=tt;
string k1=names[j];
names[j]=names[j+1];
names[j+1]=k1;
}
}
}
for(int i=0;i<teams.Length;i++)
{
if(i%b==0)
Console.WriteLine(names[i]);
}
}
}
}
``````