線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:953
推到 Plurk!
推到 Facebook!

字串排序的問題~

答題得分者是:GeorgeKu
tai1688
一般會員


發表:9
回覆:12
積分:4
註冊:2005-03-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-10 06:33:21 IP:71.104.xxx.xxx 未訂閱
昨天經blk5743大大的教導,決定用自己的方法來做,終於做出來了~可是他字串排列的怪怪的,只有第一行排列正確~拜託各位高手幫我修改一下我的字串sort的code~感激不盡~ p5.dat(原始檔) --------------------------------------------- 3211 Smith, Jimmy              76.0    80.0    85.5    83.0 4321 Adams, Jane               94.0   100.0    97.5     0.0 1234 Wang,  Andy               70.5    77.0    85.0    82.0 5678 Johnson,  susan           78.5    66.5    72.0    69.0 9320 Williams,  Donald         72.0    55.0    66.0    45.0 5436 Garcia,  Juan             84.0    82.0    77.5    91.0 1235 Nguyen,  Vickie           86.0    99.0    88.5    92.0 6324 Jackson,  Janet           80.0    88.0   100.0    88.0 2358 Vargas,  Fernado          72.5    68.0    80.0    70.0 5000 Smith,  Jane              20.0    75.0    68.0    92.0 1111 Williamson,  David        76.0    50.0    66.0    80.0 5555 Johnson,  Alexander       76.5    70.5    72.0    66.0 3400 Wong,  Suzy               60.0    60.0    60.0    60.0 9876 Johnson, Doug             99.5   100.0   100.0   100.0 ============================================== p5out.dat(輸出檔) ------------------------------------------------- Id       Name                Hw    Project   Exam   Final   Percent    Grade ------------------------------------------------------------------- 4321 Adams, Jane           94.0          100.0           97.5            0.0           72.9   C 3211 Smith, Jimmy           76.0           80.0           85.5           83.0           81.1   B 5678 Johnson, susan           78.5           66.5           72.0           69.0           71.5   C 1234 Wang, Andy           70.5           77.0           85.0           82.0           78.6   C 5436 Garcia, Juan           84.0           82.0           77.5           91.0           83.6   B 1235 Nguyen, Vickie           86.0           99.0           88.5           92.0           91.4   A 6324 Jackson, Janet           80.0           88.0          100.0           88.0           89.0   B 2358 Vargas, Fernado           72.5           68.0           80.0           70.0           72.6   C 5000 Smith, Jane           20.0           75.0           68.0           92.0           63.8   D 9320 Williams, Donald           72.0           55.0           66.0           45.0           59.5   F 5555 Johnson, Alexander           76.5           70.5           72.0           66.0           71.3   C 1111 Williamson, David           76.0           50.0           66.0           80.0           68.0   D 9876 Johnson, Doug           99.5          100.0          100.0          100.0           99.9   A 3400 Wong, Suzy           60.0           60.0           60.0           60.0           60.0   D ====================================================================
#include 
#include 
#include     typedef struct 
{
  int id;
  char lastname[20];
  char firstname[20];
  double hw;
  double project;
  double exam;
  double final;
  double percent;
  char grade;
}person;
void sort(person Person[],int a);
int main()
{      person Person[50];
  FILE *fpIn,*fpOut;
  int i=0,j,temp,a=0;
  double sc;
  int nList[14];
  
  fpIn=fopen("p5.dat","r ");
  fpOut=fopen("p5out.dat","w ");
  fputs("Id       Name                Hw    Project   Exam   Final   Percent    Grade\n",fpOut);
  fputs("-------------------------------------------------------------------\n",fpOut);
  while(!feof(fpIn))
  {
    fscanf(fpIn,"%d %s %s %lf %lf %lf %lf",&Person[i].id,&Person[i].lastname,&Person[i].firstname,&Person[i].hw,&Person[i].project,&Person[i].exam,&Person[i].final);
    i  ;
    a  ;
  }
  
   sort(Person,a);
  
  for(i=0;i=90 && sc<=100)             
         Person[i].grade='A';
     else if (sc>=80 && sc<90)          
         Person[i].grade='B';
     else if (sc>=70 && sc<80)          
         Person[i].grade='C';
     else if (sc>=60 && sc<70)
         Person[i].grade='D';   
     else if (sc<60 && sc>=0) 
         Person[i].grade='F';
    fprintf(fpOut,"%d %s %s\t%7.1lf\t%7.1lf\t%7.1lf\t%7.1lf\t%7.1lf   %c\n",Person[i].id,Person[i].lastname,Person[i].firstname,Person[i].hw,Person[i].project,Person[i].exam,Person[i].final,sc,Person[i].grade);
  }
  fclose(fpIn); 
  fclose(fpOut);
  system("pause");
}
void sort(person Person[],int a)
{
     person temp;
     int coup,i=0;
     while (i0)
      {
        temp=Person[i];
        Person[i]=Person[i 1];
        Person[i 1]=temp;
      }
      i  ;
      }
}    
GeorgeKu
中階會員


發表:1
回覆:120
積分:74
註冊:2004-10-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-10 11:22:46 IP:61.228.xxx.xxx 未訂閱
tai1688,    我把你sort的部分改為如下
void sort(person Person[],int a)
{
     person temp;
     int j=0,c=1;
     for(int i=0;i0){
                           temp=Person[i];
                           Person[i]=Person[j];
                           Person[j]=temp;
                           }
                   } 
                   c  ;
             }
}
系統時間:2024-06-02 1:49:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!