36272023-03-01 12:11:27vááááAutókódoláscsharpPartially correct 31/5028ms24352 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace auto
{
    class Program
    {
        static string DecimalToBinary(long num)
        {
            string binary = "";
            long remainder;
            while (num > 0)
            {
                remainder = num % 2;
                binary = remainder + binary;
                num /= 2;
            }
            return binary;
        }
        static long BinaryToDecimal(string binary)
        {
            long decimalNum = 0;
            int power = 0;
            for (int i = binary.Length - 1; i >= 0; i--)
            {
                int bit = binary[i] - '0';
                decimalNum += bit * (long)Math.Pow(2, power);
                power++;
            }
            return decimalNum;
        }
        static void Main(string[] args)
        {
            long szam = Convert.ToInt64(Console.ReadLine());
            string bin = DecimalToBinary(szam);
            bool siker = false;
            string kisbin = "";
            for (int i = bin.Length - 1; i > 0; i--)
            {
                if (bin[i] == '0' && bin[i - 1] == '1')
                {
                    for (int j = 0; j < bin.Length; j++)
                    {
                        if (j != i && j != i - 1) kisbin += bin[j];
                        if (j == i && j != i - 1) kisbin += '1';
                        if (j != i && j == i - 1) kisbin += '0';
                        siker = true;
                    }
                    if (siker) i = -32;
                }
            }
            long kiszam = -1; ;
            if (siker) { 
                if (kisbin[0] == '0')
                {
                    string tempbin = kisbin;
                    kisbin = "";
                    for (int i = 1; i < tempbin.Length; i++)
                    {
                        kisbin += tempbin[i];
                    }
                }
                kiszam = BinaryToDecimal(kisbin);
            }
            Console.WriteLine(kiszam);
            int valt = -1;
            for (int i = bin.Length - 1; i > 0; i--)
            {
                if (bin[i] == '1' && bin[i - 1] == '0')
                    valt = i - 1;
            }
            int nul = 0, egy = 0;
            for (int i = valt+2; i < bin.Length; i++)
            {
                if (bin[i] == '1') egy++;
                if (bin[i] == '0') nul++;
            }
            string nagybin = "";
            if (valt != -1)
            {
                for (int i = 0; i < bin.Length; i++)
                {
                    if (i > valt + 1)
                    {
                        if (nul != 0)
                        {
                            nagybin += '0';
                            nul--;
                        }
                        else
                        {
                            nagybin += '1';
                        }
                    }
                    else if (i < valt)
                    {
                        nagybin += bin[i];
                    }
                    else if (valt == i)
                    {
                        nagybin += '1';
                    }
                    else
                    {
                        nagybin += '0';
                    }
                }
                Console.WriteLine(BinaryToDecimal(nagybin));
            }
            else Console.WriteLine(BinaryToDecimal(bin+'0'));
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/027ms20692 KiB
2Accepted0/028ms21416 KiB
3Partially correct1/227ms21532 KiB
4Accepted2/228ms21920 KiB
5Partially correct1/227ms22064 KiB
6Wrong answer0/227ms21868 KiB
7Partially correct1/227ms22064 KiB
8Partially correct2/427ms22516 KiB
9Partially correct2/426ms22428 KiB
10Partially correct2/428ms22840 KiB
11Accepted4/427ms23292 KiB
12Partially correct2/426ms23424 KiB
13Partially correct2/428ms23972 KiB
14Partially correct2/427ms23928 KiB
15Accepted4/427ms24092 KiB
16Partially correct2/427ms23644 KiB
17Accepted4/427ms24352 KiB