Пример #1
0
        /// <summary>
        /// Generates a new <see cref="string" /> with random characters, where each character can be either a digit, a lowercase letter, an uppercase letter, or a combination of those. At least one of these parameters needs to be <see langword="true" />.
        /// </summary>
        /// <param name="length">The length of the generated <see cref="string" />.</param>
        /// <param name="digits"><see langword="true" /> to include digits.</param>
        /// <param name="lowerCase"><see langword="true" /> to include lowercase letters.</param>
        /// <param name="upperCase"><see langword="true" /> to include uppercase letters.</param>
        /// <returns>
        /// A new <see cref="string" /> with random characters.
        /// </returns>
        public static string AlphaNumericString(int length, bool digits, bool lowerCase, bool upperCase)
        {
            Check.ArgumentOutOfRangeEx.GreaterEqual0(length, nameof(length));
            Check.Argument(digits || lowerCase || upperCase, null, "Either of '" + nameof(digits) + "', '" + nameof(lowerCase) + "', or '" + nameof(upperCase) + "' must be true.");

            string chars = null;

            if (digits)
            {
                chars += TextResources.Digits;
            }
            if (lowerCase)
            {
                chars += TextResources.Alphabet;
            }
            if (upperCase)
            {
                chars += TextResources.Alphabet.ToUpper();
            }

            char[] charset   = chars.ToCharArray();
            char[] newString = new char[length];

            lock (MathEx._Random)
            {
                for (int i = 0; i < length; i++)
                {
                    newString[i] = MathEx._Random.NextObject(charset);
                }
            }

            return(newString.AsString());
        }
Пример #2
0
        public void Solve()
        {
            var n   = sc.Integer();
            var k   = sc.Integer();
            var deq = new Deque <int>();

            for (int i = 0; i < n; i++)
            {
                deq.PushBack(sc.Char() - 'A');
            }
            var flip = 0;

            k = Math.Min(k, 2 * n + (k % (4 * n)));
            for (int T = 0; T < k; T++)
            {
                var x = deq[0] ^ flip;
                if (x == 0)
                {
                    deq[0] ^= 1;
                }
                else
                {
                    deq.PopFront();
                    flip ^= 1;
                    deq.PushBack(flip);
                }
            }
            var c = new char[n];

            for (int i = 0; i < n; i++)
            {
                c[i] = (char)((deq[i] ^ flip) + 'A');
            }
            IO.Printer.Out.WriteLine(c.AsString());
        }
Пример #3
0
        public void Solve()
        {
            var n = sc.Integer();
            var m = sc.Integer();
            var p = sc.Scan();
            var a = sc.Integer(m);

            for (int i = 0; i < m; i++)
            {
                a[i]--;
            }
            var len = p.Length;
            var str = new char[n];

            for (int i = 0; i < n; i++)
            {
                str[i] = '?';
            }
            for (int i = 0; i < m; i++)
            {
                var ptr  = a[i];
                var next = Math.Min(a[i] + len, n);
                if (i < m - 1)
                {
                    next = Math.Min(next, a[i + 1]);
                }
                for (int j = ptr, k = 0; j < next; j++, k++)
                {
                    str[j] = p[k];
                }
            }
            var  table = StringEx.ZAlgorithm(p + str.AsString());
            long ans   = 1;

            foreach (var x in a)
            {
                if (table[len + x] >= len)
                {
                    continue;
                }
                else
                {
                    ans = 0;
                }
            }
            var cnt = 0;

            for (int i = 0; i < n; i++)
            {
                if (str[i] == '?')
                {
                    cnt++;
                }
            }
            ans = ans * ModPow(26, cnt, 1000000007);
            IO.Printer.Out.WriteLine(ans);
        }
Пример #4
0
        /// <summary>
        /// Converts the bits of this <see cref="BitArray" /> to a <see cref="string" /> containing a sequence of '0' or '1' characters.
        /// </summary>
        /// <param name="array">The <see cref="BitArray" /> to convert.</param>
        /// <returns>
        /// An equivalent sequence of '0' or '1' characters representing this <see cref="BitArray" />.
        /// </returns>
        public static string ToBitString(this BitArray array)
        {
            Check.ArgumentNull(array, nameof(array));

            char[] str = new char[array.Length];
            for (int i = 0; i < str.Length; i++)
            {
                str[i] = array[i] ? '1' : '0';
            }

            return(str.AsString());
        }