46592023-03-30 14:43:41TortelliniJrVáltakozó (75 pont)csharpRuntime error 0/7532ms27644 KiB
using System;

class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        string result = GetAlternatingString(input);
        Console.WriteLine(result);
    }

    static void Shuffle(char[] array)
    {
        Random rand = new Random();
        for (int i = array.Length - 1; i > 0; i--)
        {
            int j = rand.Next(i + 1);
            char temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
    }

    static string GetAlternatingString(string s)
    {
        char[] chars = s.ToCharArray();
        Shuffle(chars);
        for (int i = 1; i < chars.Length; i++)
        {
            if (chars[i] == chars[i - 1])
            {
                Array.Sort(chars, i, chars.Length - i);
                break;
            }
        }
        for (int i = 2; i < chars.Length; i++)
        {
            if (chars[i] == chars[i - 1])
            {
                return "-1";
            }
        }
        return new string(chars);
    }
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Runtime error0/029ms19988 KiB
2Runtime error0/029ms20552 KiB
3Runtime error0/328ms20416 KiB
4Runtime error0/328ms20896 KiB
5Runtime error0/328ms21328 KiB
6Runtime error0/328ms21724 KiB
7Runtime error0/328ms22516 KiB
8Runtime error0/330ms24404 KiB
9Runtime error0/332ms25032 KiB
10Runtime error0/332ms25400 KiB
11Runtime error0/328ms23480 KiB
12Runtime error0/328ms23428 KiB
13Runtime error0/329ms23744 KiB
14Runtime error0/328ms23884 KiB
15Runtime error0/330ms27028 KiB
16Runtime error0/330ms26852 KiB
17Runtime error0/332ms27396 KiB
18Runtime error0/330ms27484 KiB
19Runtime error0/330ms27384 KiB
20Runtime error0/330ms27588 KiB
21Runtime error0/330ms27432 KiB
22Runtime error0/630ms27616 KiB
23Runtime error0/632ms27456 KiB
24Runtime error0/632ms27644 KiB