×

# QM6P5B editorial

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[0]);
int b=int.Parse(ss[1]);
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[0];
teams[i]=ss[1];
scores[i]=int.Parse(ss[2]);
}
string aa=ss[0];
string bb=ss[1];
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]);
}
}
}
}


13311
accept rate: 0%

19.7k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,491
×775
×170
×13

question asked: 12 Feb '18, 11:09

question was seen: 117 times

last updated: 13 Feb '18, 15:59