Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static int GetWeight(string s)
- {
- int result = 0;
- for (int i = 0; i < s.Length; i++)
- {
- result += weights[s[i]];
- }
- return result;
- }
- static Dictionary<char, int> weights = new Dictionary<char, int>();
- static void Main(string[] args)
- {
- weights.Add('s', 3);
- weights.Add('n', 4);
- weights.Add('k', 1);
- weights.Add('p', 5);
- char[] arr = {'s','n','k','p'};
- int diff = int.Parse(Console.ReadLine());
- StringBuilder sample = new StringBuilder();
- List<string> all = new List<string>();
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- for (int k = 0; k < 4; k++)
- {
- for (int p = 0; p < 4; p++)
- {
- sample.Append(arr[i]);
- sample.Append(arr[j]);
- sample.Append(arr[k]);
- sample.Append(arr[p]);
- all.Add(sample.ToString());
- sample.Clear();
- }
- }
- }
- }
- StringBuilder result = new StringBuilder();
- List<string> final = new List<string>();
- for (int i = 0; i < all.Count; i++)
- {
- for (int j = 0; j < all.Count; j++)
- {
- if (Math.Abs(GetWeight(all[i]) - GetWeight(all[j])) == diff)
- {
- result.Append(all[i]);
- result.Append(all[j]);
- final.Add(result.ToString());
- result.Clear();
- }
- }
- }
- if(final.Count == 0)
- {
- Console.WriteLine("No");
- }
- else
- {
- final.Sort();
- for (int i = 0; i < final.Count; i++)
- {
- Console.WriteLine(final[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment