怎么用c写 求思路和代码

img

img


#include<stdio.h>
int main()
{
    int num[100][3];
    int n = 0;
    int t, s;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&num[i][0]);
        num[i][1] = i;
        num[i][2] = i;
    }

    for(int i = 1; i <= n - 1; i++)
     for(int j = 1; j <= n - i; j++)
    {
        if(num[j][0] < num[j+1][0])
        {
            s = num[j][0];
            num[j][0] = num[j+1][0];
            num[j+1][0] = s;
            t = num[j][1];
            num[j][1] = num[j+1][1];
            num[j+1][1] = t;
            num[num[j+1][1]][2]++;
            num[num[j][1]][2]--;
        }
    }
    for(int i = 1; i <= n; i++)
    printf("%d %d \n",num[i][0],num[i][2]);
    return 0;
}

https://leetcode-cn.com/problems/relative-ranks/solution/cyu-yan-pai-xu-hou-zai-shu-chu-by-liu-xi-c16k/

#include "stdio.h"

void main()
{
int i,j,score[10][2],temp,answer[10][2];/假设n=10,score[i][0]是answer[i],score[i][1]是score[i]/
printf("input 10 numbers:");
for(i=0;i<10;i++)/*用户动态输入*/
{
score[i][0]=i+1;
scanf("%d",&score[i][1]);
}
printf("\n");
for(j=0;j<9;j++)/*冒泡数列*/
{
for(i=0;i<9-j;i++)
{
if(score[i][1]<score[i+1][1])
{
temp=score[i][0];
score[i][0]=score[i+1][0];
score[i+1][0]=temp;
temp=score[i][1];
score[i][1]=score[i+1][1];
score[i+1][1]=temp;
}
}
}
printf("Output the serial number and award of each athlete:\n");
for(i=0;i<10;i++)
{
if(0==i)
{
printf("Gold medal is Number %d player score is %d\n",score[i][0],score[i][1]);
}
if(1==i)
{
printf("Silver medal is Number %d player score is %d\n",score[i][0],score[i][1]);
}
if(2==i)
{
printf("Bronze medal is Number %d player score is %d\n",score[i][0],score[i][1]);
}
if(i>2)
{
printf("The %d place is number %d player score is %d\n",(i+1),score[i][0],score[i][1]);
}
}
printf("\n");
}

用脑子写c,谢谢😊