Read numbers from the console given in a single line, separated by a space

前端 未结 7 1798
小蘑菇
小蘑菇 2020-12-01 12:58

I have a task to read n given numbers in a single line, separated by a space ( ) from the console.

I know how to do it whe

7条回答
  •  爱一瞬间的悲伤
    2020-12-01 13:31

    you can use this function, it's very helpful

        static List inputs = new List();
        static int input_pointer = 0;
    
        public static string cin(char sep = ' ')
        {
            if (input_pointer >= inputs.Count)
            {
                string line = Console.ReadLine();
    
                inputs = line.Split(sep).OfType().ToList();
                input_pointer = 0;
            }
    
            string v = inputs[input_pointer];
            input_pointer++;
    
            return v;
        }
    

    Example:

            for(var i =0; i

提交回复
热议问题