Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
2.7 kB
1
Indexable
Never
using System;
using System.Collections.Generic;

namespace Solution
{
    public class Solution {

        class Average {
            private int[] stack;
            private int sum;
            private int counter;
            private int amount;
            
            public Average () {
                stack = new int[50];
                counter = 0;
                sum = 0;
                amount = 0;
            }

            public int AVG50 (int num) {
                if (amount < 50) {
                    amount++;
                } else {
                    sum-=stack[counter];
                }
                sum += num;
                stack[counter] = num;
                counter = (counter + 1) % 50;
                return sum / amount;
            }
        }
    
        public static void Main(string[] args) {
            /*Average av = new Average();
            for (int i = 1; i <= 100; i++) {
                Console.WriteLine(av.AVG50(i));
            }*/
            /*int[] arr = new int[]{1, -2, 3, 2, -1000, 4, -7, 2};
            Console.WriteLine(SubSum(arr));*/

            Console.WriteLine(Match("ABCDEF", "AB.D.F"));
            Console.WriteLine(Match("ABCDEF", "AB.DF"));
            Console.WriteLine(Match("ABCDEF", "AB.DE."));
            //Console.WriteLine(Match("ABCDEF", "AB"));
            Console.WriteLine(Match("AAAAAAAAAA", "A*A"));
        }

        public static int SubSum (int[] arr) {
            int maxSum = 0,
                curSum = 0;

            for (int i = 0; i < arr.Length; i++) {
                curSum+=arr[i];

                if (curSum > maxSum){
                    maxSum = curSum;
                }
                
                if (curSum < 0)
                {
                    curSum = 0;
                }

            }
            return maxSum;
        } 

	public static bool Match(string input, string regex) {
            //if (input.Length != regex.Length) return false;
            for (int i = 0; i < input.Length; i++) {
                if (i == regex.Length) {
                    return false;
                }
                if (input[i] == regex[i] || regex[i] == '.') {
                    continue;
                } else if (regex[i] == '*') {
		    for (int j = i+1; j < input.Length; j++) {
                    	if (Match(input.Substring(j), regex.Substring(i+1))) {
			    return true;
			}
		    }
		    return false;
                } else {
                    return false;
                }
            }
            return true;
        }
    }
}