2019-06-18
#include <stdio.h>
#define SCORERADIX 0.7
typedef struct tagScore
{
double m_nSumScore;
long m_lACM;
int m_nClass;
int m_nDone;
int m_nScore;
char m_strName[15];
}SCORE,*PSCORE;
int main()
{
FILE *fpSrc = NULL,*fpDst = NULL;
PSCORE pScore = NULL;
long lCnt = 0l,i = 0l;
int nIncr = 0;
fpSrc = fopen("score.txt","r");
if (NULL == fpSrc)
{
/*提示信息*/
goto CLEARNNONE;
}
fpDst = fopen("rank.txt","w");
if (NULL == fpDst)
{
/*提示信息*/
goto CLEARNSRC;
}
if (EOF == fscanf(fpSrc,"%ld",&lCnt) || lCnt < 0l)
{
/*提示信息*/
goto CLEARNALL;
}
pScore = (PSCORE)calloc(lCnt,sizeof(SCORE));
if (NULL == pScore)
{
/*提示信息*/
goto CLEARNALL;
}
for(i = 0l;i < lCnt;++i)
{
if (EOF == fscanf(fpSrc,"%s%ld%d%d%d",pScore[i].m_strName,&pScore[i].m_lACM,&pScore[i].m_nClass,&pScore[i].m_nDone,&pScore[i].m_nScore))
{
/*提示信息*/
break;
}
pScore[i].m_nSumScore = (double)pScore[i].m_nScore * SCORERADIX;
nIncr = pScore[i].m_nClass + pScore[i].m_nDone;
if (pScore[i].m_lACM >= 80)
{
nIncr = 30;
}
else if (pScore[i].m_lACM > 30)
{
nIncr += ((pScore[i].m_lACM - 30) / 10) * 2;
if (nIncr > 30)
{
nIncr = 30;
}
}
else
{
/*do nothing*/
}
pScore[i].m_nSumScore += nIncr;
}
/*排序*/
for(i = 0l;i < lCnt;++i)
{
/*........*/
}
/*输出*/
for(i = 0l;i < lCnt;++i)
{
fprintf(fpDst,"%s %f",pScore[i].m_strName,pScore[i].m_nSumScore);
}
CLEARNALL:
free(pScore);
fclose(fpDst);
CLEARNSRC:
fclose(fpSrc);
CLEARNNONE:
return 0;
}
#include <stdio.h>
#define SCORERADIX 0.7
typedef struct tagScore
{
double m_nSumScore;
long m_lACM;
int m_nClass;
int m_nDone;
int m_nScore;
char m_strName[15];
}SCORE,*PSCORE;
int main()
{
FILE *fpSrc = NULL,*fpDst = NULL;
PSCORE pScore = NULL;
long lCnt = 0l,i = 0l;
int nIncr = 0;
fpSrc = fopen("score.txt","r");
if (NULL == fpSrc)
{
/*提示信息*/
goto CLEARNNONE;
}
fpDst = fopen("rank.txt","w");
if (NULL == fpDst)
{
/*提示信息*/
goto CLEARNSRC;
}
if (EOF == fscanf(fpSrc,"%ld",&lCnt) || lCnt < 0l)
{
/*提示信息*/
goto CLEARNALL;
}
pScore = (PSCORE)calloc(lCnt,sizeof(SCORE));
if (NULL == pScore)
{
/*提示信息*/
goto CLEARNALL;
}
for(i = 0l;i < lCnt;++i)
{
if (EOF == fscanf(fpSrc,"%s%ld%d%d%d",pScore[i].m_strName,&pScore[i].m_lACM,&pScore[i].m_nClass,&pScore[i].m_nDone,&pScore[i].m_nScore))
{
/*提示信息*/
break;
}
pScore[i].m_nSumScore = (double)pScore[i].m_nScore * SCORERADIX;
nIncr = pScore[i].m_nClass + pScore[i].m_nDone;
if (pScore[i].m_lACM >= 80)
{
nIncr = 30;
}
else if (pScore[i].m_lACM > 30)
{
nIncr += ((pScore[i].m_lACM - 30) / 10) * 2;
if (nIncr > 30)
{
nIncr = 30;
}
}
else
{
/*do nothing*/
}
pScore[i].m_nSumScore += nIncr;
}
/*排序*/
for(i = 0l;i < lCnt;++i)
{
/*........*/
}
/*输出*/
for(i = 0l;i < lCnt;++i)
{
fprintf(fpDst,"%s %f",pScore[i].m_strName,pScore[i].m_nSumScore);
}
CLEARNALL:
free(pScore);
fclose(fpDst);
CLEARNSRC:
fclose(fpSrc);
CLEARNNONE:
return 0;
}