Home > Net >  C # 26 letters from a to z to English respectively for 1 to 26 points, write a program to input word
C # 26 letters from a to z to English respectively for 1 to 26 points, write a program to input word

Time:09-26

If the English of the 26 letters from a to z respectively made up for 1 to 26 points, please write a program to input any words, the letters of the secondary points together, to see whether the result is 100 points, when the result is 100 points over, such as ATTITIDE=100%

CodePudding user response:

For homework?
String into a Char array, converted to ASCII, on a (97) + 1 score,
There is a way to use a dictionary Dict the table, and then, in turn, values

CodePudding user response:

First of all, to construct a set of 1 a, 2 b.

 
Var ar=Enumerable. Range (65, 26).
Select (d=& gt; ASCIIEncoding. ASCII. Get string (new byte [] {} (byte) d)).
Select ((d (I)=& gt; New {I=I + 1, d}) ToList ();


Then according to the input string dismantling sum.

 
Var STR="ABC".
Var strar=STR. ToCharArray (). The Select (d=& gt; Which oString (). The ToUpper ()). ToList ();
Var store=0;
The foreach (var item in strar)
{
Store +=ar. FirstOrDefault (d=& gt; D.d==item). I;
}
Console. WriteLine (${store "} ");


As to the problem of accumulation is a cycle to receive... Done by oneself

CodePudding user response:

The enumeration, and then divide each enumeration value accumulation of the characters.
  •  Tags:  
  • C#
  • Related