Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to use C# to read the three digits in each line of the txt file below and turn them into independent numbers, and calculate how many numbers have the same hundreds and tens digits?
How to use C# to read the three digits in each line of the txt file below and turn them into independent numbers, and calculate how many numbers have the same hundreds and tens digits?

using?System;

using?System.Collections.Generic;

using?System.Linq;

using?System. IO;

namespace?ConsoleApplication1

{

class?Program

{

static?void?Main (string[]?args)

{

//Read all lines

string[]?nums?=?File.ReadAllLines("txt1. txt");

//From string-->integer number

int[]?values?=?new?int[nums.Length];

< p>for?(int?i?=?0;?i?

{

//?The purpose of dividing 10 is to keep only The lower hundreds and tens digits

//?For example,?321?/10?-->32

//?To facilitate subsequent judgment

values[i]?=?int.Parse(nums[i])?/?10;

}

//?Use Linq for judgment

/ /?Use ?linq's ?group?by? to count the number of occurrences of different values

var?qry?=?from?v?in?values ??group?v?by?v?into?x select ?new { V?=?x.Key, C?=?x.Count(?) };

//Output statistical results?

foreach?(var?v? in?qry)

{

Console.WriteLine("There are {1} numbers with a hundred and ten digits of {0}",?v.V,?v.C);

}

}

}

}