我该如何更改密码? [英] How Do I Change The Code?
本文介绍了我该如何更改密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello亲爱的编码员
以下是在课堂上找到最高分(成绩)的代码。如果2个或更多学生获得相同的高分(成绩)怎么办? john 90,david 90?
使用系统;
命名空间 sample1
{
class 计划
{
public static void Main ( string [] args)
{
int c,HighMark = 0 ,place = 0 ;
字符串 [] A = { John , David, Clare, Robert, Michael, < span class =code-string> Peter, Steve, Daniel, Alex, Bart};
int [] B = { 56 , 78 , 95 , 23 , 95 , 87 , 61 , 77 , 45 , 33 };
for (c = 0 ; c< = B.Length-1; c ++){
如果(B [c] > = HighMark){
HighMark =公元前];
place = c; }
}
Console.WriteLine( 获得最高分的人: + A [位]);
Console.Write( 按任意键继续......);
Console.ReadKey( true );
}
}
}
解决方案
一种可能性是将最高分数收集到一个单独的列表并最后显示列表内容。类似
静态 void Main( string [] args)
{
System.Collections.Generic.List< int> places = new System.Collections.Generic.List< int>();
int HighMark = 0 ;
字符串 [] A = { John , David, Clare, Robert, Michael, < span class =code-string> Peter, Steve, Daniel, Alex, Bart};
int [] B = { 56 , 78 , 95 , 23 , 95 , 87 , 61 , 77 , 45 , 33 };
for ( int counter = 0 ; counter < = B.Length - 1 ; counter ++)
{
if (B [counter] > HighMark)
{
place 。明确();
places.Add(counter);
HighMark = B [counter];
}
其他 如果(B [counter] == HighMark)
{
places.Add(counter);
}
}
foreach ( int place 中的code-keyword>
{
Console.WriteLine( 获得最高分的人: + A [地方]);
}
Console.Write( 按任意键继续......);
Console.ReadKey( true );
} < / int > < / int >
使用Linq可以很容易地生成一组排序最高的成绩/学生:// required
使用系统。 Collections.Generic;
使用 System.Linq;
private void ReportGrades()
{
字符串 [] A = { John, David, < span class =code-string> Clare, Robert, Michael, Peter, Steve, Daniel, Alex, Bart};
int [] B = { 56 , 78 , 95 , 23 , 95 , 87 , 61 , 77 , 45 , 33 };
Dictionary< int,List< string>> grades = new Dictionary< int,List< string>>();
for ( int i = 0 ; i < A.Length; i ++)
{
if (!grades.Keys.Contains(B [i]))成绩[B [i]] = 新列表< string>();
等级[B [i]]。加(A [i]);
}
var gradesDescending = grades.OrderByDescending(grade = > grade.Key)。ToList();
foreach ( var gradeResult in gradesDescending)
{
Console.Write( 等级:{0} \t,gradeResult.Key.ToString());
foreach ( var name in gradeResult.Value)
{
Console.Write( {0} ,名字);
}
Console.WriteLine();
}
}
// 示例输出:
等级: 95 Clare Michael
等级: 87 彼得
等级: 78 David
等级: 77 Daniel
等级: 61 Steve
等级: 56 John
等级: 45 Alex
等级: 33 Bart
等级: 23 Robert < / string > 跨度>
Hello Dear Coders
Here is a code for to find the highest mark(grade) in the class.What about if 2 or more students get the same high mark(grade)? john 90,david 90 ?
using System;
namespace sample1
{
class Program
{
public static void Main(string[] args)
{
int c, HighMark=0, place=0;
String [] A={"John", "David","Clare","Robert","Michael","Peter","Steve","Daniel","Alex","Bart"};
int [] B={56,78,95,23,95,87,61,77,45,33};
for (c=0;c<=B.Length-1;c++){
if(B[c]>= HighMark){
HighMark=B[c];
place=c; }
}
Console.WriteLine("The Person Get The Highest Mark: "+A[place]);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
解决方案
One possibility is to gather the highest marks into a separate list and display the list content in the end. Something like
static void Main(string[] args) { System.Collections.Generic.List<int> places = new System.Collections.Generic.List<int>(); int HighMark = 0; String[] A = { "John", "David", "Clare", "Robert", "Michael", "Peter", "Steve", "Daniel", "Alex", "Bart" }; int[] B = { 56, 78, 95, 23, 95, 87, 61, 77, 45, 33 }; for (int counter = 0; counter <= B.Length - 1; counter++) { if (B[counter] > HighMark) { places.Clear(); places.Add(counter); HighMark = B[counter]; } else if (B[counter] == HighMark) { places.Add(counter); } } foreach (int place in places) { Console.WriteLine("The Person Get The Highest Mark: " + A[place]); } Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }</int></int>
Using Linq it becomes very easy to produce an ordered set of grades/students with the highest-score:// required using System.Collections.Generic; using System.Linq; private void ReportGrades() { String[] A = { "John", "David", "Clare", "Robert", "Michael", "Peter", "Steve", "Daniel", "Alex", "Bart" }; int[] B = { 56, 78, 95, 23, 95, 87, 61, 77, 45, 33 }; Dictionary<int,List<string>> grades = new Dictionary<int,List<string>>(); for (int i = 0; i < A.Length; i++) { if (! grades.Keys.Contains(B[i])) grades[B[i]] = new List<string>(); grades[B[i]].Add(A[i]); } var gradesDescending = grades.OrderByDescending(grade => grade.Key).ToList(); foreach (var gradeResult in gradesDescending) { Console.Write("Grade: {0}\t", gradeResult.Key.ToString()); foreach (var name in gradeResult.Value) { Console.Write("{0} ", name); } Console.WriteLine(); } } // sample output: Grade: 95 Clare Michael Grade: 87 Peter Grade: 78 David Grade: 77 Daniel Grade: 61 Steve Grade: 56 John Grade: 45 Alex Grade: 33 Bart Grade: 23 Robert </string>
这篇关于我该如何更改密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文