洛谷编译时没有加-unsafe,这咋整?

P3612 [USACO17JAN] Secret Cow Code S

Ff_c109 @ 2021-05-17 10:31:25

写了半天,发现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


by ud2_ @ 2021-05-17 14:12:29

?

Write(a[(int) (n - 1)]);

|