洛谷编译时没有加-unsafe,这咋整?
查看原帖
洛谷编译时没有加-unsafe,这咋整?
123538
Ff_c109楼主2021/5/17 10:31

写了半天,发现Int64根本就不能拿来当下标用。想了半天,忽然灵机一动用了指针,结果居然还真行。 然后我用之前RE的试点试了一下,发现可以了。高高兴兴的提交上去,然后发现。。。。Compile Error

using System;
using static System.Console;

namespace main
{
    class program
    {
        static string a;
        static string[] inputBuffer;
        static int Main(string[] args)
        {
            Int64 n, num = 0;
            inputBuffer = ReadLine().Split(' ');
            a = inputBuffer[0];
            n = int.Parse(inputBuffer[1]);
            num = a.Length;
            while (num < n)
            {
                Int64 i = num;
                while (n > i * 2)
                    i *= 2;
                n -= (i + 1);
                if (n == 0)
                    n = i;
            }
            unsafe
            {
                void* temp_1 = &n;
                Write(a[*(int*)temp_1 - 1]);
            }
            return 0;
        }
    }
}

/tmp/compiler_3bib_hbr/src(26,13): error CS0227: Unsafe code requires the `unsafe' command line option to be specified
Compilation failed: 1 error(s), 0 warnings


2021/5/17 10:31
加载中...