46572023-03-30 14:39:27TortelliniJrVáltakozó (75 pont)csharpRuntime error 0/7532ms27348 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 = 1; i < chars.Length; i++)
        {
            if (chars[i] == chars[i - 1])
            {
                return "-1";
            }
        }
        return new string(chars);
    }
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Runtime error0/030ms19632 KiB
2Runtime error0/029ms20040 KiB
3Runtime error0/329ms20456 KiB
4Runtime error0/329ms21300 KiB
5Runtime error0/329ms21952 KiB
6Runtime error0/329ms21448 KiB
7Runtime error0/329ms22184 KiB
8Runtime error0/332ms24172 KiB
9Runtime error0/332ms24616 KiB
10Runtime error0/330ms25148 KiB
11Runtime error0/330ms22544 KiB
12Runtime error0/329ms23264 KiB
13Runtime error0/330ms23248 KiB
14Runtime error0/329ms23612 KiB
15Runtime error0/332ms25972 KiB
16Runtime error0/332ms26420 KiB
17Runtime error0/332ms26396 KiB
18Runtime error0/332ms26540 KiB
19Runtime error0/332ms26768 KiB
20Runtime error0/332ms26584 KiB
21Runtime error0/332ms27348 KiB
22Runtime error0/632ms27160 KiB
23Runtime error0/632ms27096 KiB
24Runtime error0/632ms27144 KiB