You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lx125/工作量统计.c

244 lines
5.3 KiB

6 years ago
#include "stdio.h"
#include "stdlib.h"
#define FILENAME "worker.bin"
#define N 20
/*******************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*******************************************************/
struct worker
{
int number; /*<2A><><EFBFBD><EFBFBD>*/
int counts; /*<2A><><EFBFBD><EFBFBD>*/
int grade; /*<2A><><EFBFBD><EFBFBD>*/
};
/*******************************************************
<EFBFBD><EFBFBD>ʾ<EFBFBD>˵<EFBFBD>
*******************************************************/
void xinxi()
{
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("+ ְ<><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>ϵͳ +\n");
printf("+ +\n");
printf("+ 1. ְ<><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD> +\n");
printf("+ +\n");
printf("+ 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> +\n");
printf("+ +\n");
printf("+ 3. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> +\n");
printf("+ +\n");
printf("+ 4. <20><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD>Ž<EFBFBD><C5BD><EFBFBD><EFBFBD><EFBFBD>Ϣɾ<CFA2><C9BE> +\n");
printf("+ +\n");
printf("+ 5. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> +\n");
printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
/*******************************************************
<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
*******************************************************/
readFromFile(struct worker w[])
{
FILE *fp=NULL;
int i=0;
fp=fopen(FILENAME,"rb"); /*<2A><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>*/
if(fp!=NULL)
{
while(!feof(fp)) /*<2A><><EFBFBD>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD>ѧ<EFBFBD><D1A7>*/{
if(i>=N)
break;
if(fread(w+i,sizeof(w),1,fp)==1)
i++;
}
fclose(fp);
}
return i;
}
/*******************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
*******************************************************/
int f(struct worker w[],int length)
{
int i=length;
while(i<N){
printf("<EFBFBD><EFBFBD>%d<><64>ְ<EFBFBD><D6B0>\n",i);
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD>):\n");/*<2A><><EFBFBD><EFBFBD><EBB9A4>*/
scanf("%d",&w[i].number);
if(w[i].number==0)
break;
printf("\n");
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
scanf("%d",&w[i].counts);
printf("\n");
i++;
}
return i;
}
/*******************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
*******************************************************/
void input(struct worker w[],int length)
{
int i=1;
int number,counts;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%d",&number);
while(number!=0)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%d",&counts);
for(i=0;i<length;i++)
if(w[i].number==number)
{
w[i].counts+=counts;
break;
}
if(i>=length)
printf("<EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%d",&number);
}
}
////////////////////////////////////////////////////////////////////////////////
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򲢱<EFBFBD><F2B2A2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */////////////////////////////////////////////////////////////////////////////////
void sortCounts(struct worker w[],int length)
{
int i=0,j=0,k=0;
struct worker s;
for(i=0;i<length;i++)
{
k=i;
for(j=i+1;j<length;j++)for(j=i+1;j<length;j++)
if(w[j].counts<w[k].counts)
k=j;
/* <20><><EFBFBD><EFBFBD> w[i] and w[k] */
s = w[k];
w[k] =w[i];
w[i] = s;
}
if(length>0)
w[0].grade =1;
for(i=1;i<length;i++)
if(w[i].counts==w[i-1].counts)
w[i].grade=w[i-1].grade;
else
w[i].grade=w[i-1].grade+1;
}
////////////////////////////////////////////////////////////////////////////////
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD>ͬһ<CDAC><D2BB><EFBFBD>ε<EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵĹ<C7B5><C4B9>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD><EFBFBD>*/
///////////////////////////////////////////////////////////////////////////////
void sortNumber(struct worker w[],int length)
{
int i=0;
int grade,count;
if(length>0)
{ while(i<length)
{
count=0;
grade=w[i].grade;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d ", grade);
printf(" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d ",w[i].counts);
printf("%s","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
while(i<length)
{
if(grade==w[i].grade)
{printf("%d ",w[i].number);
count++;
}
else
break;
i++;
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d\n",count);
}
}
else
printf("ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
/********************************************************
<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
********************************************************/
int delet(struct worker w[],int length,int stuNum){
int i,j;
char choice;
for(i=0;i<length;i++)
{
if(stuNum==w[i].number)
{
printf("<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>");
printf("%d\n",w[i].number);
break;
}
}
if(i<length)
{
printf("<EFBFBD><EFBFBD>ȷʵҪɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?(Y/N)");
scanf("%c",&choice);
if(choice=='Y'||choice=='y')
{
for(j=i;j<length;j++)
w[j]=w[j+1];
length--;
printf("ɾ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!\n");
}
}
else
printf("\nָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
return length;
}
/********************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
********************************************************/
void writeToFile(struct worker w[],int length){
FILE *fp=NULL;
int i=0;
fp=fopen(FILENAME,"wb");
if(fp==NULL)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
exit(0);
}
for(i=0;i<length;i++)
fwrite(w+i,sizeof(w),1,fp);
fclose(fp);
}
int main (){
int choice;
struct worker w[N];
int NUM;
char stuName[100];
int stuNum;
int length=0;
length=readFromFile(w);//<2F><><EFBFBD><EFBFBD>
do
{ xinxi();
scanf("%d",&choice);
switch(choice)
{ case 1:
length=f(w,length);
break;
case 2:
input(w,length);
break;
case 3:
sortCounts(w,length);
sortNumber(w,length);
break;
case 4:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&stuNum);
length=delet(w,length,stuNum);
break;
case 5:
{
writeToFile(w,length);//<2F><><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD><EFBFBD>\n");
exit(0);
}
default:
{printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
}
}}while(1);
}