C#练习题答案: 积分总额【难度:0级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#练习题答案: 积分总额【难度:0级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3367字,纯文字阅读大概需要5分钟。
内容图文
积分总额【难度:0级】:
答案1:
using System.Linq;
using System;
public static class Kata {
public static int TotalPoints(string[] games) {
int total = 0;
foreach (string game in games) {
if (game[0] > game[2])
total += 3;
else if (game[0] == game[2])
total += 1;
}
return total;
}
}?
答案2:
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public static class Kata {
public static int TotalPoints(string[] games) {
return games.Select(x =>
{
var values = x.Split(':').Select(int.Parse);
if (values.ElementAt(0) > values.ElementAt(1))
{
return 3;
}
return values.ElementAt(0) < values.ElementAt(1)
? 0
: 1;
}).Sum(x => x);
}
}?
答案3:
using System.Linq;
public static class Kata {
public static int TotalPoints(string[] games) {
return games.Select(x => CalculatePoints(x)).Sum();
}
public static int CalculatePoints(string game){
var scores = game.Split(":");
if(int.Parse(scores[0]) > int.Parse(scores[1])) return 3;
if(int.Parse(scores[0]) < int.Parse(scores[1])) return 0;
return 1;
}
}?
答案4:
using System.Linq;
public static class Kata {
public static int TotalPoints(string[] games) =>
games.Select(e =>(x:e[0], y:e[2])).Select(e => e.x > e.y ? 3 : e.x == e.y ? 1 : 0).Sum();
}?
答案5:
using System;
public static class Kata {
public static int TotalPoints(string[] games)
{
var points = 0;
foreach (var item in games)
{
points += (item[0] > item[2]) ? 3 : (item[0] == item[2]) ? 1 : 0;
}
return points;
}
}?
答案6:
using System.Linq;
public static class Kata {
public static int TotalPoints(string[] games)
{
return games.Where(x => x[0] > x[2]).Count()*3 + games.Where(y=>y[0]==y[2]).Count();
}
}?
答案7:
using System.Linq;
public static class Kata {
public static int toInt(char c){
switch(c){
case '0': return 0; break;
case '1': return 1; break;
case '2': return 2; break;
case '3': return 3; break;
case '4': return 4; break;
case '5': return 5; break;
case '6': return 6; break;
case '7': return 7; break;
case '8': return 8; break;
default: return 9;
}
}
public static int TotalPoints(string[] games) {
int points = 0;
foreach(string c in games){
int x = toInt(c[0]);
int y = toInt(c[2]);
if(x>y) points+=3;
else if(x==y)points+=1;
}
return points;
}
}?
答案8:
using System;
using System.Linq;
public static class Kata
{
public static int TotalPoints(string[] games)
{
return games.Sum(matchResult => InterpreteMatch(matchResult, GetScoreByChampionshipRules));
}
private static int InterpreteMatch(string match, Func<int, int, int> calculateScore)
{
int scoreTeamA= (int)char.GetNumericValue(match[0]);
int scoreTeamB = (int)char.GetNumericValue(match[2]);
return calculateScore(scoreTeamA, scoreTeamB);
}
private static int GetScoreByChampionshipRules(int a, int b)
{
if(a == b) return 1;
if(a < b) return 0;
return 3;
}
}?
答案9:
using System.Linq;
public static class Kata {
public static int TotalPoints(string[] games) {
int result = 0;
foreach(var score in games)
{
result += score[0] > score[2] ? 3 :
score[0] == score[2] ? 1 : 0;
}
return result;
}
}?
答案10:
using System;
using System.Linq;
public static class Kata {
public static int TotalPoints(string[] games) {
int point = 0;
for (int i = 0; i < games.Length; i++)
{
string[] scores = new string[2];
scores = games[i].Split(":");
int score1 = Convert.ToInt32(scores[0]);
int score2 = Convert.ToInt32(scores[1]);
if (score1 > score2)
{
point += 3;
}
else if (score1 == score2)
{
point++;
}
}
return point;
}
}?
内容总结
以上是互联网集市为您收集整理的C#练习题答案: 积分总额【难度:0级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战全部内容,希望文章能够帮你解决C#练习题答案: 积分总额【难度:0级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。