Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int[] massive = Array.ConvertAll(
- Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries),
- int.Parse
- );
- int m = int.Parse(Console.ReadLine());
- HashSet<KeyValuePair<int, int>> set = new HashSet<KeyValuePair<int, int>>();
- for (int i = 0; i < m; i++)
- {
- var input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- int first = int.Parse(input[0]);
- int second = int.Parse(input[1]);
- if (first < second)
- {
- set.Add(new KeyValuePair<int, int>(second, first));
- }
- else
- {
- set.Add(new KeyValuePair<int, int>(first, second));
- }
- }
- for (int i = 0; i < n; i++)
- {
- bool flag = true;
- for (int j = 0; j < n - i - 1; j++)
- {
- int a = massive[j];
- int b = massive[j + 1];
- if (set.Contains(new KeyValuePair<int, int>(a, b)))
- continue;
- if (a > b)
- {
- flag = false;
- int temp = massive[j];
- massive[j] = massive[j + 1];
- massive[j + 1] = temp;
- }
- }
- if (flag == true)
- {
- break;
- }
- }
- Console.WriteLine(String.Join(" ", massive));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement