题目考试成绩排序
要求
1实现从高到低排序
2统计分组人数及百分比(分为大于等于90807060及不及挌)
3分数数据来源于文本文件
4处理结果保存在一个文本文件中
c#成绩排序,求帮助
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答 默认 最新
关注 C#代码如下
using System; using System.IO; using System.Linq; namespace ScoreSorter { class Program { static void Main(string[] args) { // 读取文件中的分数 var scores = File.ReadAllLines("scores.txt") .Select(line => int.Parse(line)) .ToList(); // 从高到低排序 scores.Sort((a, b) => b.CompareTo(a)); // 统计分组人数及百分比 var scoreGroups = new int[6]; foreach (var score in scores) { if (score >= 90) { scoreGroups[0]++; } else if (score >= 80) { scoreGroups[1]++; } else if (score >= 70) { scoreGroups[2]++; } else if (score >= 60) { scoreGroups[3]++; } else { scoreGroups[4]++; } } // 计算百分比 var scoreGroupPercents = new double[6]; for (int i = 0; i < scoreGroups.Length; i++) { scoreGroupPercents[i] = (double)scoreGroups[i] / scores.Count; } // 将排序后的分数和分组统计信息写入文件 using (var writer = File.CreateText("output.txt")) { // 写入排序后的分数 foreach (var score in scores) { writer.WriteLine(score); } // 写入分组人数及百分比 writer.WriteLine("90+: " + scoreGroups[0] + " " + scoreGroupPercents[0]); writer.WriteLine("80+: " + scoreGroups[1] + " " + scoreGroupPercents[1]); writer.WriteLine("70+: " + scoreGroups[2] + " " + scoreGroupPercents[2]); writer.WriteLine("60+: " + scoreGroups[3] + " " + scoreGroupPercents[3]); writer.WriteLine("<60: " + scoreGroups[4] + " " + scoreGroupPercents[4]); } } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度