第十二章-又来了一堆数据

1大奖赛现场统分

#include 
#include 

#define N 20

typedef struct a
{
    int  numberA[N];
    float score[N];
    int  numberJ[N];
    float scoreIJ[N][N];
    float scoreJ[N];
}GAME;

void Play(int a, int ju, GAME* game);

int main()
{
    int a, j;
    GAME game;
    printf("How many Athletes?\n");
    scanf("%d", &a);
    printf("How many judges?\n");
    scanf("%d", &j);
    printf("Scores of Athletes:\n");
    Play(a, j, &game);
    return 0;
}

void Play(int a, int ju, GAME* game)
{
    float max = 0, min = 10, sum = 0;
    for (int i = 0; i < a; i++)
    {
        sum = 0; max = 0; min = 10;
        printf("Athlete %d is playing.\n", i+1);
        printf("Please enter his number code:\n");
        scanf("%d", &(game->numberA[i]));
        for (int j = 0; j < ju; j++)
        {
            
            game->numberJ[j] = j+1;
            printf("Judge %d gives score:\n", j+1);
            scanf("%f", &(game->scoreIJ[i][j]));
            if (game->scoreIJ[i][j] > max)
                max = game->scoreIJ[i][j];
            if (game->scoreIJ[i][j] < min)
                min = game->scoreIJ[i][j];
            sum += game->scoreIJ[i][j];
        }
        game->score[i] = (sum - max - min) / (ju - 2);
        printf("Delete a maximum score:%.1f\n", max);
        printf("Delete a minimum score:%.1f\n", min);
        printf("The final score of Athlete %d is %.3f\n", game->numberA[i], game->score[i]);
    }
    for (int j = 0; j < ju; j++)
    {
        float temp = 0;
        for (int i = 0; i < a; i++)
        {
            temp += pow(game->scoreIJ[i][j] - game->score[i], 2);
        }
        temp = sqrt(temp / a);
        game->scoreJ[j] = 10 - temp;
    }
    printf("Order of Athletes:\n");
    printf("order\tfinal score\tnumber code\n");
    for (int i=0; iscore[j] < game->score[j + 1])
            {
                temps = game->score[j]; game->score[j] = game->score[j + 1]; game->score[j + 1] = temps;
                tempNo = game->numberA[j]; game->numberA[j] = game->numberA[j + 1]; game->numberA[j + 1] = tempNo;
            }
        }
    for (int i = 0; i < a; i++)
        printf("%5d\t%11.3f\t%6d\n", i+1, game->score[i], game->numberA[i]);
    printf("Order of judges:\n");
    printf("order\tfinal score\tnumber code\n");
    for (int i = 0; i < ju - 1; i++)
        for (int j = 0; j < ju - i - 1; j++)
        {
            float temps;
            int tempNo;
            if (game->scoreJ[j] < game->scoreJ[j + 1])
            {
                temps = game->scoreJ[j]; game->scoreJ[j] = game->scoreJ[j + 1]; game->scoreJ[j + 1] = temps;
                tempNo = game->numberJ[j]; game->numberJ[j] = game->numberJ[j + 1]; game->numberJ[j + 1] = tempNo;
            }
        }
    for (int i = 0; i < ju; i++)
        printf("%5d\t%11.3f\t%6d\n", i+1, game->scoreJ[i], game->numberJ[i]);
    printf("Over!Thank you!\n");
}

2学生成绩管理系统V3.0(4分)

输出格式错了,唉,我对这个成绩管理系统真的是日了狗了。菜鸡的自我消遣时间...

#include 
#include 

typedef struct student
{
    long number;
    char name[10];
    float score;
}STUDENT;

void Play(int n, STUDENT *stu);
void Input(int n, STUDENT* stu);
void SumAver(int n, STUDENT * stu);
void Sort(int n, STUDENT* stu, int flag);//flag为0代表成绩降序排列,1->升序排列;2->学号升序排列;4->姓名升序排列
void Search(int n, STUDENT* stu, int flag);
void Statistics(int n, STUDENT * stu);
    

int main()
{
    int n;
    STUDENT stu[30];
    printf("Input student number(n<30):\n");
    scanf("%d", &n);
    Play(n, stu);
    return 0;
}

void Play(int n, STUDENT *stu)
{
    int choice;
    do
    {
        printf("Management for Students' scores\
            \n1.Input record\
            \n2.Caculate total and average score of course\
            \n3.Sort in descending order by score\
            \n4.Sort in ascending order by score\
            \n5.Sort in ascending order by number\
            \n6.Sort in dictionary order by name\
            \n7.Search by number\
            \n8.Search by name\
            \n9.Statistic analysis\
            \n10.List record\
            \n0.Exit\
            \nPlease Input your choice:\n");
        scanf("%d", &choice);
        switch (choice)
        {
        case 1:Input(n, stu); break;
        case 2:SumAver(n, stu); break;
        case 3:Sort(n, stu, 0); break;
        case 4:Sort(n, stu, 1); break;
        case 5:Sort(n, stu, 2); break;
        case 6:Sort(n, stu, 4); break;
        case 7:Search(n, stu, 0); break;
        case 8:Search(n, stu, 1); break;
        case 9:Statistics(n, stu); break;
        case 10:Sort(n, stu, 5); break;
        case 0:printf("End of program!"); break;
        default:printf("Input error!\n");
        }
    } while (choice);
}
void Statistics(int n ,STUDENT* stu)
{
    int s[6] = {0};
    float temp;
    for (int i = 0; i < n; i++)
    {
        temp = (stu + i)->score;
        if (temp < 60)
            s[0]++;
        else if (temp < 70)
            s[1]++;
        else if (temp < 80)
            s[2]++;
        else if (temp < 90)
            s[3]++;
        else if (temp < 100)
            s[4]++;
        else if (temp == 100)
            s[5]++;
    }
    printf("<60\t%d\t%.2f%%\n", s[0], (100.0*s[0]) / n);
    printf("60-69\t%d\t%.2f%%\n", s[1], (100.0*s[1]) / n);
    printf("70-79\t%d\t%.2f%%\n", s[2], (100.0*s[2]) / n);
    printf("80-89\t%d\t%.2f%%\n", s[3], (100.0*s[3]) / n);
    printf("90-99\t%d\t%.2f%%\n", s[4], (100.0*s[4]) / n);
    printf("100\t%d\t%.2f%%\n", s[5], (100.0*s[5]) / n);
}

void Search(int n, STUDENT* stu, int flag)//flag为0表示按学号查找,为1表示按姓名查找
{
    long No;
    char Name[10];
    if (flag == 0)
    {
        printf("Input the number you want to search:\n");
        scanf("%ld", &No);
    }
        
    else if (flag == 1)
    {
        printf("Input the name you want to search:\n");
        getchar();
        gets(Name);
    }
        
    for (int i = 0; i < n; i++)
    {
        if (flag == 0 && (stu + i)->number == No)
        {
            printf("%ld\t%s\t%.0f\n", (stu+i)->number, (stu+i)->name, (stu+i)->score);
            return;
        }
        else if (flag == 1 && strcmp((stu + i)->name, Name) == 0)
        {
            printf("%ld\t%s\t%.0f\n", (stu + i)->number, (stu + i)->name, (stu + i)->score);
            return;
        }
    }
    printf("Not found!\n");
}



void Sort(int n, STUDENT* stu, int flag)
{
    STUDENT* p[30];
    STUDENT* temp  = stu;
    for (int i = 0; i < n; i++)
        p[i] = stu + i;
    for (int i=0; iscore < p[j+1]->score)
                {
                    temp = p[j]; p[j] = p[j + 1]; p[j + 1] = temp;
                    //printf("%.0f\n", p[j + 1]->score);
                }
            }
            else if (flag == 1)
            {
                if (p[j]->score > p[j + 1]->score)
                {
                    temp = p[j]; p[j] = p[j + 1]; p[j + 1] = temp;
                }
                
            }
            else if (flag == 2)
            {
                if (p[j]->number > p[j + 1]->number)
                {
                    temp = p[j]; p[j] = p[j + 1]; p[j + 1] = temp;
                }
            }
            else if (flag == 4 || flag ==5)
            {
                if (strcmp(p[j]->name, p[j + 1]->name) >= 0)
                {
                    temp = p[j]; p[j] = p[j + 1]; p[j + 1] = temp;
                }
                    
            }   
        }
    if (flag ==0)
        printf("Sort in descending order by score:\n");
    else if (flag == 1)
        printf("Sort in ascending order by score:\n");
    else if (flag ==2)
        printf("Sort in ascending order by number:\n");
    else if (flag == 4)
        printf("Sort in dictionary order by name:\n");
    for (int i = 0; i < n; i++)
    {
        printf("%ld\t%s\t%.0f\n", p[i]->number, p[i]->name, p[i]->score);
    }
    
}


void SumAver(int n, STUDENT* stu)
{
    float sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += (stu+i)->score;
    }
    printf("sum=%.0f,aver=%.2f\n", sum, sum / n);
}

void Input(int n, STUDENT* stu)
{
    STUDENT* p = stu;
    printf("Input student's ID, name and score:\n");
    for (int i = 0; i < n; i++)
    {
        scanf("%ld", &(p->number));
        getchar();
        gets(p->name);
        scanf("%f", &(p->score));
        p++;
    }
    
}

3单词接龙

# include
#include 

int main()
{
    int lena, lenb;
    char word[2][20];
    gets(word[0]);
    gets(word[1]);
    lena = strlen(word[0]);
    lenb = strlen(word[1]);
    //strrev(word[0]);
    for (int i = 0; i < lena; i++)
    {
        if (strncmp(word[0] + i, word[1], 1) == 0)
        {
            if (strncmp(word[0] + i, word[1], lena - i) == 0)
            {
                puts(word[0] + i);
                break;
            }
        }
    }
    return 0;
}

4分数比较

# include
#include 

int main()
{
    int numeratorA, denominatorA, numeratorB, denominatorB;
    printf("Input two FENSHU:\n");
    scanf("%d/%d,%d/%d", &numeratorA, &denominatorA, &numeratorB, &denominatorB);
    if ((numeratorA * denominatorB) > (numeratorB* denominatorA))
        printf("%d/%d>%d/%d\n", numeratorA, denominatorA, numeratorB, denominatorB);
    else if ((numeratorA * denominatorB) == (numeratorB* denominatorA))
        printf("%d/%d=%d/%d\n", numeratorA, denominatorA, numeratorB, denominatorB);
    else
        printf("%d/%d<%d/%d\n", numeratorA, denominatorA, numeratorB, denominatorB);
    return 0;
}

5百万富翁的换钱计划

# include

int main()
{
    double ToRich, ToStranger=0;
    double temp = 0.01;
    ToRich = (1e5) * 30;
    for (int i = 0; i < 30; i++)
    {
        ToStranger += temp;
        temp *= 2;
    }
    printf("to Stranger: %.2lf yuan\n", ToStranger);
    printf("to Richman: %.2lf yuan\n", ToRich);
    return 0;
}

6用计数控制的循环实现正数累加求和

# include

int main()
{
    int number;
    int sum = 0;
    int count = 0;
    do
    {
        printf("Input a number:\n");
        scanf("%d", &number);
        if (number > 0)
        {
            sum += number;
            count++;
        }
    } while (number);
    printf("sum=%d,count=%d\n", sum, count);
    return 0;
}

7平方根表

# include
#include

int main()
{
    
    int n;
    printf("Input n(n<=10):\n");
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
        printf("%7d", i);
    //printf("\n");

    for (int i = 0; i < n; i++)
    {
        printf("\n");
        printf("%d", i);
        for (int j = 0; j < n; j++)
            printf("%7.3f", sqrt(10.0 * i + j));
        
    }
    return 0;
}

8最大公约数

# include
#include

int gcd(int x, int y);

int main()
{
    int a, b;
    int max;
    int count = 0;
    printf("Input a and b:\n");
    scanf("%d,%d", &a, &b);
    if (a > 0 && b > 0)
    {
        max = gcd(a, b);
        for (int i = 1; i <= max; i++)
        {
            if (max % i == 0)
            {
                count++;
                printf("Common factor %d is %d\n", count, max / i);
            }
                
        }
            
    }
    return 0;
}

int gcd(int x, int y)
{
    return y ? gcd(y, x % y) : x;
}

923根火柴游戏

# include
#include

void Move(void);

int main()
{
    //int left=23;
    printf("Game start!\n");
    printf("Note: the maximum number is 3\n");
    Move();
    return 0;
}

void Move(void)
{
    int match;
    int left = 23;
    do 
    {
        printf("Please enter the number of matches you are moving:\n");
        scanf("%d", &match);
        while (match > 3 || (left - match)<0 )
        {
            printf("The number you entered is wrong,please re-enter!\n");
            printf("Please enter the number of matches you are moving:\n");
            scanf("%d", &match);
        }
        printf("The number of matches you are moving is:%d\n", match);
        printf("The number of matches left is:%d\n", left -= match);
        if (left == 0)
            printf("I'm sorry. You lost!\n");
        else
        {
            if (left < 3)
                match = 1;
            else
                (match = left % 3 + 1);
            printf("The number of matches that have been moved by the computer is:%d\n", match);
            printf("The number of matches left is:%d\n", left -= match);
            if (left == 0)
                printf("Congratulations!You won!\n");
        }
    } while (left);
}

你可能感兴趣的:(第十二章-又来了一堆数据)