CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 17:37:50 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=bf6091b0ad1f2e0b135ee483043cd3880bc6013f78da9196c8bb19db75e61e7fa%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22VQG0Ofcy7p4N2Y_VUau--nYxueK3cC5H%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d020aece94c179-BLR
import org.apache.spark.{SparkConf, SparkContext}object GradeAnalysis { d - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.spark.{SparkConf, SparkContext}
- object GradeAnalysis {
- def main(args: Array[String]): Unit = {
- val conf = new SparkConf().setAppName("Grade Analysis").setMaster("local")
- val sc = new SparkContext(conf)
- // 读取成绩文件
- val hadoopGrades = sc.textFile("grade/Hadoop.txt")
- val sparkGrades = sc.textFile("grade/Spark.txt")
- // 解析文件内容
- val hadoopScores = hadoopGrades.map(line => {
- val parts = line.split(" ")
- (parts(0), parts(1).toInt)
- })
- val sparkScores = sparkGrades.map(line => {
- val parts = line.split(" ")
- (parts(0), parts(1).toInt)
- })
- // 合并两个RDD
- val allScores = hadoopScores.union(sparkScores)
- // 计算每名学生的总成绩和次数
- val studentScores = allScores.map {
- case (student, score) => (student, (score, 1))
- }
- val totalScores = studentScores.reduceByKey {
- case ((score1, count1), (score2, count2)) => (score1 + score2, count1 + count2)
- }
- // 计算平均成绩
- val averageScores = totalScores.map {
- case (student, (totalScore, count)) => (student, totalScore.toDouble / count)
- }
- // 输出每名学生的平均成绩
- println("Average Scores:")
- averageScores.collect().foreach {
- case (student, avgScore) => println(s"$student: $avgScore")
- }
- sc.stop()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ W
JavaScript | 4 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 9
JavaScript | 12 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ V
JavaScript | 15 sec ago | 0.24 KB
-
⭐✅ Trading Profit Method ✅ NEVER SEEN BEFORE...
JavaScript | 21 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ X
JavaScript | 23 sec ago | 0.24 KB
-
⭐⭐Exchange Exploit⭐⭐ Y
JavaScript | 27 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 31 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ 3
JavaScript | 33 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand