luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/PTIT025 #117

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Chi tiết bài tập - Luyện Code Online

https://luyencode.net/problem/PTIT025

namnam2303 commented 2 years ago

Admin xem giúp em code sao lại sai được không ạ

phong11011 commented 2 years ago

Mọi người xem giúp e code chạy bình thường nhưng ko accept được a·

Xem code AC

#include typedef struct{ int toan; int li; int cpp; }Diem; typedef struct { char name[99]; Diem diem; }Student; int main(int argc, char const *argv[]) { int n; scanf("%d", &n); Student student[n]; for (int i = 0; i < n; ++i) { // printf("Ten: "); fflush(stdin); gets(student[i].name); } for (int i = 0; i < n; ++i) { scanf("%d", &student[i].diem.toan); } for (int i = 0; i < n; ++i) { scanf("%d", &student[i].diem.li); } for (int i = 0; i < n; ++i) { scanf("%d", &student[i].diem.cpp); } int max = student[0].diem.toan + student[0].diem.li + student[0].diem.cpp; for (int i = 1; i < n; ++i) { if (max < student[i].diem.toan + student[i].diem.li + student[i].diem.cpp) { max = student[i].diem.toan + student[i].diem.li + student[i].diem.cpp; } } for (int i = 0; i < n; ++i) { if (max == student[i].diem.toan + student[i].diem.li + student[i].diem.cpp) { printf("%s %d %d %d\n", student[i].name, student[i].diem.toan, student[i].diem.li, student[i].diem.cpp); } } return 0; }

hoangdev0 commented 1 year ago
Xem code AC:
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
// typedef long long ll;
// const int N = 1e6+2;
// int n;
struct sv
{
  string name;
  int toan, li, tin, diem;
  bool operator>(sv other)
  {
      return diem > other.diem;
  }
};
bool cmp(sv a, sv b)
{
  return a.diem > b.diem;
}
int main()
{
  freopen("begin.inp", "r", stdin);
  freopen("begin.out", "w", stdout);
  fast();
  int n;
  cin >> n;
  cin.ignore();
  vector<sv> a(n);
  for (auto &x : a)
      getline(cin, x.name);
  for (auto &x : a)
      cin >> x.toan;
  for (auto &x : a)
      cin >> x.li;
  for (auto &x : a)
      cin >> x.tin;
  int m = 0;
  for (auto &x : a)
  {
      x.diem = x.tin + x.toan + x.li;
      m = max(m, x.diem);
  }
  // cout << m;
  // sort(a.begin(), a.end(), cmp);
  for (const auto &x : a)
      if (x.diem == m)
          cout << x.name << " " << x.toan << " " << x.li << " " << x.tin << endl;
  return 0;
}
ThuanNqt commented 1 year ago

MÌNH CÓ HƯỚNG DẪN CHI TIẾT TRONG CODE

Xem code AC

``cpp #include using namespace std; typedef long long ll; #define fast() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) int main(){ fast(); int n;cin>>n; cin.ignore();//xóa dấu enter đi tránh bị trôi lệnh int a[5][n+2];//mảng 2 chiều lưu điểm vector v;//dùng để lưu tên của mỗi người v.push_back("0");//mình dùng chỉ số của tên bắt đầu từ 1 cho dễ int m=n;//nhớ lưu m=n vì khi này m=m-1 và cứ thế giảm đi nếu không lưu lại sẽ sai while(m--){ string s;getline(cin,s); v.push_back(s); } int p[101],cnt=0,res=-1e9; //mảng p[] lưu chỉ số cột có tổng điểm lớn nhất //cnt là chỉ số chạy của mảng p[] //res để lưu kỷ lục tổng điểm lớn nhất for(int i=1;i<=3;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; } } for(int j=1;j<=n;j++){ int sum=0;//tính tổng điểm của 1 người for(int i=1;i<=3;i++){ sum+=a[i][j]; } if(sum>res){ res=sum; p[0]=j;//tìm ra vị trí lớn nhất trong mảng rồi lưu nó vào p[0] cnt=1; }else if(sum==res){ p[cnt++]=j;//tìm các vị trí có tổng bằng với res } } //MỌI NGƯỜI CHÚ Ý KHÔNG IN RA DẤU "CÁCH" VÀ DẤU "ENTER" THỪA for(int i=0;i

ThuanNqt commented 1 year ago

Mình sửa lại 1 xíu (^_^)

Xem code AC

```cpp #include using namespace std; typedef long long ll; #define fast() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) int main(){ fast(); int n;cin>>n; cin.ignore();//xóa dấu enter đi tránh bị trôi lệnh int a[5][n+2];//mảng 2 chiều lưu điểm vector v;//dùng để lưu tên của mỗi người v.push_back("0");//mình dùng chỉ số của tên bắt đầu từ 1 cho dễ int m=n;//nhớ lưu m=n vì khi này m=m-1 và cứ thế giảm đi nếu không lưu lại sẽ sai while(m--){ string s;getline(cin,s); v.push_back(s); } int p[101],cnt=0,res=-1e9; //mảng p[] lưu chỉ số cột có tổng điểm lớn nhất //cnt là chỉ số chạy của mảng p[] //res để lưu kỷ lục tổng điểm lớn nhất for(int i=1;i<=3;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; } } for(int j=1;j<=n;j++){ int sum=0;//tính tổng điểm của 1 người for(int i=1;i<=3;i++){ sum+=a[i][j]; } if(sum>res){ res=sum; p[0]=j;//tìm ra vị trí lớn nhất trong mảng rồi lưu nó vào p[0] cnt=1; }else if(sum==res){ p[cnt++]=j;//tìm các vị trí có tổng bằng với res } } //MỌI NGƯỜI CHÚ Ý KHÔNG IN RA DẤU "CÁCH" VÀ DẤU "ENTER" THỪA for(int i=0;i

btLong402 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

```cpp #include using namespace std; #define SIZE 101 #define fto(i, a, n) for(i = a; i <= n; i++) char Name[SIZE][SIZE]; int LY[SIZE], Toan[SIZE], Cpp[SIZE]; int SUM[SIZE]; int n,i; int main(){ cin >> n; getchar(); fto(i,1,n){ fgets(Name[i], SIZE, stdin); strtok(Name[i], "\n"); } fto(i, 1, n) cin >> Toan[i]; fto(i, 1, n) cin >> LY[i]; fto(i, 1, n) cin >> Cpp[i]; fto(i, 1, n) SUM[i] = Toan[i] + LY[i] + Cpp[i]; int Max = 0; fto(i, 1, n - 1) Max = max(Max, max(SUM[i], SUM[i+1])); fto(i, 1, n){ if(SUM[i] == Max) cout << Name[i] << " " << Toan[i] << " " << LY[i] << " " << Cpp[i] << endl; } return 0; } ```