@python.20s: Python cơ bản #python #coding #learning

Python 20s
Python 20s
Open In TikTok:
Region: VN
Monday 14 September 2026 03:24:23 GMT
2976
115
2
3

Music

Download

Comments

naman_nek
nam_ann :
import std; using namespace std; using namespace literals;   int main() {  auto lines = vector‹string›();    {   auto file = ifstream("DIEM.TXT");   auto text = ""s;   while (getline(file, text))    lines.emplace_back(text);  }    auto result = vector‹string›();    for (auto const& line : lines) {   auto [name, s_math, s_literature] = line | views::split(' ') | ranges::to‹tuple‹auto, auto, auto››();      auto math = stod(s_math);   auto literature= stod(s_literature);      auto average = (math + literature) / 2;   auto rank = ""sv;      if (average >= 9)    rank = "Xuất sắc";   else if (average >= 8)    rank = "Giỏi";   else if (average >= 6.5)    rank = "Khá";   else if (average >= 5)    rank = "Trung bình";   else    rank = "Yếu";      result.emplace_back(format("{} {:.2f} {}", name, average, rank));  }    {   auto file = ofstream("KETQUA.txt");      file ‹‹ "Tên TB Xếp loại";   file ‹‹ result | views::join_with('\n') | ranges::to‹string›();  }    println("Đã ghi kết quả vào KETQUA.txt"); }
2026-09-14 12:39:11
1
eric_huy_tran
Huy Trần :
use std::fs; struct Student { name: String, score1: f64, score2: f64, } impl Student { fn average(&self) -> f64 { (self.score1 + self.score2) / 2.0 } fn rank(&self) -> &str { match self.average() { x if x >= 8.0 => "Gioi", x if x >= 6.5 => "Kha", x if x >= 5.0 => "Trung binh", _ => "Yeu", } } } fn main() { let data = fs::read_to_string("DIEM.TXT") .expect("Khong the mo file DIEM.TXT"); let students: Vec = data .lines() .map(|line| { let mut parts = line.split_whitespace(); Student { name: parts.next().unwrap().to_string(), score1: parts.next().unwrap().parse().unwrap(), score2: parts.next().unwrap().parse().unwrap(), } }) .collect(); let mut result = String::new(); for student in &students { result.push_str(&format!( "{} {:.1} {}\n", student.name, student.average(), student.rank() )); } fs::write("KETQUA.TXT", result) .expect("Khong the ghi file KETQUA.TXT"); }
2026-09-14 12:49:19
1
To see more videos from user @python.20s, please go to the Tikwm homepage.

Other Videos


About