Announcement

Collapse
No announcement yet.

Nơi luyện tập về lập trình C - Môn Nhập môn Lập trình

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Originally posted by 14520589 View Post
    Em bị Wrong Answer luôn rồi thầy. :shot:
    Em sai bộ test:
    999999999999999999999999999999 + 99999999999999999999999999

    Originally posted by 14520662 View Post
    [ATTACH=CONFIG]15586[/ATTACH]
    Thầy ới rốt cuộc để input sao :shot:
    Nhân tiện cho em xin luôn bộ test bài này :cry:
    Bài đó đề nhầm em ơi: đúng là nhâp từ màn hình.
    Em bị sau nếu chuỗi có đoạn ". Den" hay ". Ben"
    Last edited by toannv; 30-12-2014, 21:17.

    Comment


    • Thầy ơi ở bài Z:Tam giác
      Nếu như Tam Giác vuông cân thì sao Thầy?

      Comment


      • Originally posted by 14520725 View Post
        Thầy ơi ở bài Z:Tam giác
        Nếu như Tam Giác vuông cân thì sao Thầy?
        Thì em ghi tam giác cân.

        Comment


        • PHP Code:
          //Tam giac
          #include <stdio.h>
          #include <math.h>
          main(){
              
          long x1,y1,x2,y2,x3,y3;
              while(
          scanf("%ld%ld%ld%ld%ld%ld",&x1,&y1,&x2,&y2,&x3,&y3)>=1){
                  
          //Tinh do dai:
                  
          double c[3];
                  
          c[0]=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
                  
          c[1]=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
                  
          c[2]=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
                  
          //Kiem tra co phai là tam giac
                  
          int kq=1;
                  for(
          int i=0;i<3;i++){
                      if(
          c[i]==c[(i+1)%3]+c[(i+2)%3]) kq=0;
                  }
                  
          //kiem tra tam giac vuong
                  
          int v=0;
                  if(
          kq!=0)
                  for(
          int i=0;i<3;i++){
                      
          float m = (float) c[i]*c[i];
                      
          float n = (float) (c[(i+1)%3])*(c[(i+1)%3])+(c[(i+2)%3])*(c[(i+2)%3]);
                      if(
          m==nv=1;
                  }
                  
          //kiem tra tam giac can hay deu
                  
          int ca=0,d=0;
                  if(
          c[0]==c[1]||c[1]==c[2]||c[0]==c[2])
                      {
                          
          ca=1;
                          if(
          c[0]==c[1]&&c[1]==c[2]) d=1;
                      }
                  
          //xuat kq:
                  
          if(kq==0printf("0\n");
                      else{
                          if(
          d==1) {
                          
          printf("4\n");
                          
          ca=0;}
                          if(
          ca==1){
                          
          printf("3\n");
                          
          v=0;}
                          if(
          v==1printf("2\n");
                          if(
          ca==0&&v==0&&d==0printf("1\n");
                      }
              }

          Em làm ra kết quả đúng như test mẫu nhưng submit thì bị wrong anwser.... thầy xem giúp em với

          Comment


          • tạo acc giùm em vs thầy ơi
            14520846@gm.uit.edu.vn

            Comment


            • Originally posted by 14520846 View Post
              tạo acc giùm em vs thầy ơi
              14520846@gm.uit.edu.vn
              Em sử dụng các account có sẵn ở đó đi

              Comment


              • Originally posted by 14520692 View Post
                PHP Code:
                //Tam giac
                #include <stdio.h>
                #include <math.h>
                main(){
                    
                long x1,y1,x2,y2,x3,y3;
                    while(
                scanf("%ld%ld%ld%ld%ld%ld",&x1,&y1,&x2,&y2,&x3,&y3)>=1){
                        
                //Tinh do dai:
                        
                double c[3];
                        
                c[0]=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
                        
                c[1]=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
                        
                c[2]=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
                        
                //Kiem tra co phai là tam giac
                        
                int kq=1;
                        for(
                int i=0;i<3;i++){
                            if(
                c[i]==c[(i+1)%3]+c[(i+2)%3]) kq=0;
                        }
                        
                //kiem tra tam giac vuong
                        
                int v=0;
                        if(
                kq!=0)
                        for(
                int i=0;i<3;i++){
                            
                float m = (float) c[i]*c[i];
                            
                float n = (float) (c[(i+1)%3])*(c[(i+1)%3])+(c[(i+2)%3])*(c[(i+2)%3]);
                            if(
                m==nv=1;
                        }
                        
                //kiem tra tam giac can hay deu
                        
                int ca=0,d=0;
                        if(
                c[0]==c[1]||c[1]==c[2]||c[0]==c[2])
                            {
                                
                ca=1;
                                if(
                c[0]==c[1]&&c[1]==c[2]) d=1;
                            }
                        
                //xuat kq:
                        
                if(kq==0printf("0\n");
                            else{
                                if(
                d==1) {
                                
                printf("4\n");
                                
                ca=0;}
                                if(
                ca==1){
                                
                printf("3\n");
                                
                v=0;}
                                if(
                v==1printf("2\n");
                                if(
                ca==0&&v==0&&d==0printf("1\n");
                            }
                    }

                Em làm ra kết quả đúng như test mẫu nhưng submit thì bị wrong anwser.... thầy xem giúp em với
                Em sai ở bộ test
                280 341 7 526 749 23
                480 43 388 555 317 949

                Comment


                • dạ em cảm ơn thầy

                  Comment


                  • Thầy xem giúp em code e lỗi bộ test nào?!
                    bộ test
                    280 341 7 526 749 23
                    480 43 388 555 317 949
                    em chạy ra 1. (ba điểm này không thẳng hàng nên tạo thành tam giác, em dùng tỉ lệ để xét, nên k có sai số)

                    PHP Code:
                    #include <stdio.h>
                    #include <math.h>

                    typedef struct tagDiem
                    {
                        
                    int x,y;
                    }
                    DIEM;

                    typedef struct Phanso
                    {
                        
                    int Tu;
                        
                    int Mau;
                    }
                    Phanso;

                    Phanso Toigian(Phanso a)
                    {
                        if (
                    a.Tu==|| a.Mau==0)    return a;    //neu co tu hoac mau = 0 thi xem nhu la toi gian
                        
                    int TuMau;
                        
                    Tu abs(a.Tu);
                        
                    Mau=abs(a.Mau);
                        while (
                    Tu!=Mau)
                            if (
                    Tu>Mau)
                                
                    Tu=Tu-Mau;
                            else
                                
                    Mau=Mau-Tu;
                        
                    a.Tu=a.Tu/Tu;
                        
                    a.Mau=a.Mau/Tu;
                        if (
                    a.Mau<0)
                        {
                            
                    a.Mau= - a.Mau;
                            
                    a.Tu= - a.Tu;
                        }
                        return 
                    a;
                    }

                    int DoDaiCanh(DIEM M,DIEM N)                //em khong lay can vi nhu v se sai so
                    {
                        
                    int l;
                        
                    = (M.x-N.x)*(M.x-N.x) + (M.y-N.y)*(M.y-N.y);
                        return 
                    l;
                    }

                    char Trung(DIEM ADIEM B)                    //kiem tra 2 diem trung nhau
                    {
                        if (
                    A.x==B.x&&A.y==B.y)    return 1;
                        return 
                    0;
                    }

                    char ThangHang(DIEM ADIEM BDIEM C)        //kiem tra 3 diem thang hang
                    {
                        
                    Phanso a,b;
                        
                    a.Tu B.A.x;                        //vecto AB
                        
                    a.Mau B.A.y;
                        
                    b.Tu C.A.x;                        //vecto AC
                        
                    b.Mau C.A.y;
                        
                    Toigian(a);
                        
                    Toigian(b);
                        if (
                    a.Tu==&& b.Tu ==0)        return 1;
                        if (
                    a.Mau==&& b.Mau ==0)        return 1;
                        if (
                    a.Tu==b.Tu&&a.Mau==b.Mau)    return 1;
                        return 
                    0;
                    }

                    char TamGiac(DIEM ADIEM BDIEM C)
                    {
                        if (
                    Trung(A,B)||Trung(A,C)||Trung(C,B))
                            return 
                    0;
                        if (
                    ThangHang(A,B,C))
                            return 
                    0;
                        return 
                    1;
                    }

                    main()
                    {
                        
                    int AB,BC,AC;
                        
                    DIEM A,B,C;
                        
                    char result;    //0:Khong la tg
                                        //1:Tgiac thuong
                                        //2:Tgiac vuong
                                        //3:Tgiac can
                                        //4:Tgiac deu
                        
                    while (scanf("%d%d%d%d%d%d",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y)>0)
                        {
                            
                    AB DoDaiCanh(A,B);
                            
                    AC DoDaiCanh(A,C);
                            
                    BC DoDaiCanh(B,C);
                            
                            
                    int Max,Min;
                            
                    Max = (((AB>AC)?AB:AC)>BC)?((AB>AC)?AB:AC):BC;
                            
                    Min = (((AB<AC)?AB:AC)<BC)?((AB<AC)?AB:AC):BC;
                            
                            if (!
                    TamGiac(A,B,C))
                                
                    result=0;
                            else if (
                    Min == (AB+BC+AC-Min-Max) || Max == (AB+BC+AC-Min-Max))
                            {
                                
                    result=3;                    //tam giac can
                                
                    if (Max == Min)    result=4;    //tam giac deu
                            
                    }
                            else if (
                    Max == Min + (AB+BC+AC-Max-Min))
                                
                    result=2;                    //tam giac vuong
                            
                    else result=1;                    //tam giac thuong
                            
                    printf("%d\n",result);
                        }

                    Comment


                    • Dạ Thầy ơi xem giùm em mấy bài này. Test tay thì ra kết quả nhưng lúc chấm bị báo lỗi. E cảm ơn ạ!

                      1. Bài: Chuỗi đọc ngược
                      PHP Code:
                      # include <stdio.h>
                      # include <string.h>
                      # include <stdlib.h>

                      //In Dao Nguoc
                      void xuatnguoc(char *s)
                      {
                          
                      int a[50];
                          
                      char *p;
                          
                      char temp[20];
                          
                      int vtri = -1;
                          
                      int dem = -1;

                          while ((
                      strchr(vtri 1' ')) != NULL)
                          {
                              
                      dem++;
                              
                      vtri p-s;
                              
                      a[dem] = vtri;
                          }

                          if (
                      dem == -1)
                          {
                              
                      printf("%s"s);
                          }

                          else
                          {
                              
                      strncpy(tempa[dem] + 1strlen(s) - a[dem] - 1);
                              
                      temp[strlen(s) - a[dem] - 1] = NULL;
                              
                      printf("\n\n\n%s"temp);
                              
                              for (
                      int i dem0i--)
                              {
                                  
                      strncpy(tempa[1], a[i] - a[1]);
                                  
                      temp[a[i] - a[1]] = NULL;
                                  
                      printf("%s"temp);
                              }
                              
                              
                              
                      strncpy(tempsa[0]);
                              
                      temp[a[0]] = NULL;
                              
                      printf(" %s\n"temp);
                          }
                          

                      }

                      int main()
                      {
                          
                      char s[200];

                          while (
                      strlen(gets(s)) > 0)
                          {
                              
                      xuatnguoc(s);
                          }
                          
                          
                      printf("\n");
                          return 
                      0;

                      2. Bài: Cộng số lớn
                      PHP Code:
                      #include <stdio.h>
                      #include <string.h>

                      void tong(char *s1char *s2)
                      {
                          
                      int i1i2;

                          
                      i1 strlen(s1) - 1;
                          
                      i2 strlen(s2) - 1;

                          while (
                      i1 >= || i2 >= 0)
                          {
                              if (
                      i1 >= i2 && i2>=0)
                              {
                                  if (
                      i1 0)
                                  {
                                      if (
                      s1[i1] + s2[i2] - 48 >= 10)
                                      {
                                          
                      s1[i1 1] += 1;
                                      }
                                      
                      s1[i1] = (s1[i1] + s2[i2] - 48 2) % 10 48;
                                  }
                                  else 
                      s1[i1]=s1[i1]+s2[i2]-48;
                              }
                              else if (
                      i1 >= i2 && i2<0)
                              {
                                  if (
                      i1 0)
                                  {
                                      if (
                      s1[i1] + '0' 48 >= 10)
                                      {
                                          
                      s1[i1 1] += 1;
                                      }
                                      
                      s1[i1] = (s1[i1] + '0' 48 2) % 10 48;
                                  }
                                  else 
                      s1[i1] = s1[i1] + '0' 48;
                              }
                              else if (
                      i2>i1 && i1>=0)
                              {
                                  if (
                      i2 0)
                                  {
                                      if (
                      s1[i1] + s2[i2] - 48 >= 10)
                                      {
                                          
                      s2[i2 1] += 1;
                                      }
                                      
                      s2[i2] = (s1[i1] + s2[i2] - 48 2) % 10 48;
                                  }
                                  else 
                      s2[i2] = s1[i1] + s2[i2]-48;
                              }
                              else if (
                      i2 >= i2 && i1<0)
                              {
                                  if (
                      i2 0)
                                  {
                                      if (
                      s2[i2] + '0' 48 >= 10)
                                      {
                                          
                      s2[i2 1] += 1;
                                      }
                                      
                      s2[i2] = (s2[i2] + '0' 48 2) % 10 48;
                                  }
                                  else 
                      s2[i2] = s2[i2] + '0' 48;
                              }
                              
                      i1--;
                              
                      i2--;
                          }

                          if (
                      strlen(s1) >= strlen(s2))
                          {
                              while (
                      s1[0] == '0')
                                  
                      strcpy(&s1[0], &s1[1]);
                              
                              if (
                      s1[0] - 48 >= 10)
                              {
                                  
                      s1[0] = (s1[0] - 48) % 10 48;
                                  
                      printf("1");
                              }

                              if (
                      s1[0] != NULL)    puts(s1);
                              else 
                      printf("0\n");
                          }
                          else
                          {
                              while (
                      s2[0] == '0')
                                  
                      strcpy(&s2[0], &s2[1]);

                              if (
                      s2[0] - 48 >= 10)
                              {
                                  
                      s2[0] = (s2[0] - 48) % 10 48;
                                  
                      printf("1");
                              }

                              if (
                      s2[0] != NULL)    puts(s2);
                              else 
                      printf("0\n");

                          }
                      }


                      int main()
                      {
                          
                      int n;
                          
                      char s1[200], s2[200];

                          
                      FILE *fi fopen("BaiF.inp""r");

                          
                      fscanf(fi"%d", &n);

                          for (
                      int i 1<= ni++)
                          {
                              
                      fscanf(fi"%s", &s1);
                              
                      fscanf(fi"%s", &s2);
                              
                      tong(s1s2);
                              
                      printf("\n");
                          }

                          
                      fclose(fi);
                          return 
                      0;

                      3. Bài: Lãi Suất
                      PHP Code:
                      #include <stdio.h>

                      void thanhtien(double &tienint thangfloat laisuat)
                      {
                          for (
                      int i 1<= thangi++)
                          {
                              
                      tien tien tien*laisuat;
                          }
                      }

                      int main()
                      {
                          
                      int n;
                          
                      double tien;
                          
                      int thang;
                          
                      float laisuat;

                          
                      FILE *fi fopen("FileI.inp""r");
                          
                      fscanf(fi"%d", &n);
                          for (
                      int i 1<= ni++)
                          {
                              
                      fscanf(fi"%lld %d %f", &tien, &thang, &laisuat);
                              
                      thanhtien(tienthanglaisuat);
                              
                      printf("%lld\n"tien);
                          }
                          
                          
                      fclose(fi);
                          return 
                      0;

                      4. Bài: Tính điểm trung bình
                      PHP Code:
                      #include <stdio.h>
                      #include <string.h>

                      //
                      struct _MonHoc
                      {
                          
                      float Diem;
                          
                      int TC;
                      }
                      typedef MonHoc;

                      //
                      struct _SV
                      {
                          
                      char MSSV[10];
                          
                      char HoTen[30];
                          
                      MonHoc Mon[20];
                          
                      float DTB;
                      }
                      typedef SV;


                      // Ham Doc Du Lieu Tu File
                      void Inp(FILE *fiSV SinhVien[50], int &n)
                      {
                          
                      int iSTC;
                          
                      float s;

                          while (!
                      feof(fi))
                          {
                              
                      fscanf(fi"%s\n", &SinhVien[n].MSSV);
                              
                      fgets(SinhVien[n].HoTen30fi);
                              
                      SinhVien[n].HoTen[strlen(SinhVien[n].HoTen) - 1] = '\0';
                              
                      0;
                              
                      0;
                              
                      STC 0;

                              while (
                      1)
                              {
                                  
                      fscanf(fi"%f(%d)", &SinhVien[n].Mon[i].Diem, &SinhVien[n].Mon[i].TC);
                                  
                      + (SinhVien[n].Mon[i].Diem)*(SinhVien[n].Mon[i].TC);
                                  
                      STC += SinhVien[n].Mon[i].TC;
                                  
                      i++;
                                  if (
                      fgetc(fi) == 10 || feof(fi)) break;
                              }
                              
                      SinhVien[n].DTB STC;
                              
                      n++;
                          }
                          
                      fclose(fi);
                      }


                      // Ham Sap Xep
                      void Sort(SV SinhVien[50], int n)
                      {
                          
                      SV temp;

                          for (
                      int i 01i++)
                              for (
                      int j 1n;j++)
                                  if (
                      SinhVien[i].DTB SinhVien[j].DTB)
                                  {
                                      
                      temp SinhVien[i];
                                      
                      SinhVien[i] = SinhVien[j];
                                      
                      SinhVien[j] = temp;
                                  }
                      }


                      // Vi Thu
                      void Out(SV SinhVien[50], int n)
                      {
                          
                      int ViThu[50];
                          
                      ViThu[0] = 1;
                          
                      printf("\n\n%s\t%s\t%4.2f\t%d"SinhVien[0].MSSVSinhVien[0].HoTenSinhVien[0].DTBViThu[0]);

                          for (
                      int i 1ni++)
                          {
                              if (
                      SinhVien[i].DTB == SinhVien[1].DTB)
                                  
                      ViThu[i] = ViThu[1];
                              else
                                  
                      ViThu[i] = 1;
                              
                      printf("\n\n%s\t%s\t%4.2f\t%d"SinhVien[i].MSSVSinhVien[i].HoTenSinhVien[i].DTBViThu[i]);
                          }

                      }


                      //
                      int main()
                      {
                          
                      FILE *fi fopen("BaiG.inp""r");
                          
                      SV SinhVien[50];
                          
                      int n 0;

                          
                      Inp(fiSinhVienn);
                          
                      Sort(SinhVienn);
                          
                      Out(SinhVienn);

                          
                      printf("\n\n\n");
                          return 
                      0;

                      Last edited by 14520990; 08-01-2015, 20:49.

                      Comment


                      • Dạ Thầy cho e hỏi lỗi "Run-time check failure #2 - Stack around the variable 'a' was corrupted" của bài này là sao ạ?

                        PHP Code:
                        #include <stdio.h>

                        int main()
                        {
                            
                        int nmi;
                            
                        100;

                            
                        long a[100], b[100];

                            
                        printf("Nhap m: ");
                            
                        scanf("%d", &m);

                            for (
                        2<= ni++)
                                
                        a[i] = i;

                            
                        2;
                            
                        int dem = -1;
                            while (
                        <= n)
                            {
                                if (
                        a[i] > 0)
                                {
                                    for (
                        int j 1<= nj++)
                                        if (
                        j%== 0)
                                            
                        a[j] = 0;
                                    
                        dem++;
                                    
                        b[dem] = i;
                                }
                                
                        i++;
                            }

                            
                        printf("\n\nSo nguyen to thu m: %ld"b[m]);

                            
                        printf("\n\n\n");
                            return 
                        0;

                        Comment


                        • Originally posted by 14520990 View Post
                          Dạ Thầy cho e hỏi lỗi "Run-time check failure #2 - Stack around the variable 'a' was corrupted" của bài này là sao ạ?

                          PHP Code:
                           
                          Đây là bài nào hả em hả em?
                          Last edited by toannv; 12-01-2015, 15:23.

                          Comment


                          • Dạ bài M thuật sàng nguyên tố Eratosthense

                            Comment


                            • Originally posted by 14520990 View Post
                              Dạ bài M thuật sàng nguyên tố Eratosthense
                              Bài này Tôi chạy được ổn mà em?
                              Tuy nhiên nếu nộp lên hệ thống ACM thì sẽ bị lỗi do không đúng do chỗ input, output. Và bài toán có thể bắt buộc tìm số nguyên tố thứ 400.000

                              Comment


                              • [QUOTE=14520990;312971]Dạ Thầy ơi xem giùm em mấy bài này. Test tay thì ra kết quả nhưng lúc chấm bị báo lỗi. E cảm ơn ạ!

                                Originally posted by 14520990 View Post
                                1. Bài: Chuỗi đọc ngược
                                PHP Code:
                                 
                                Em xem ví dụ của bài D, không nên dùng while (strlen(gets(s)) > 0)

                                Originally posted by 14520990 View Post
                                2. Bài: Cộng số lớn
                                PHP Code:
                                 
                                Em chú ý, mỗi dòng cách nhau chỉ 1 cái xuống hàng thôi.
                                Và chỗ FILE *fi = fopen("BaiF.inp", "rt") em chú ý có chữ t trong rt nữa



                                Originally posted by 14520990 View Post
                                3. Bài: Lãi Suất
                                PHP Code:
                                 
                                Bài này em sai chỗ FILE *fi = fopen("FileI.inp", "r"); tên đúng là FILE *fi = fopen("BaiI.inp", "r");




                                Originally posted by 14520990 View Post
                                4. Bài: Tính điểm trung bình
                                PHP Code:
                                 
                                Nếu SV chỉ có điểm 1-2 môn học thì chương trình em chạy sai.


                                Tôi quên mất bài này, Tôi xin trả lời như sau:
                                Last edited by toannv; 12-01-2015, 15:54.

                                Comment

                                LHQC

                                Collapse
                                Working...
                                X