prvcj22/du5/program.c

116 lines
2.8 KiB
C
Raw Permalink Normal View History

2022-04-08 09:27:38 +00:00
#include<stdio.h>
#include <string.h>
#include <stdbool.h>
bool similar = false;
bool wrong = false;
struct x1
{
int idx;
char array[60];
};
int main(){
struct x1 x1[50];
int n_p = 0;
int i1=0;
while(i1 >=0)
{
i1=i1+1;
char idx1[60];
int idx2 =0;
int nikita = scanf("%d", &idx2);
if (nikita == -1)
{
break;
}
if (idx2 == 0)
{
wrong = true;
}
fgets(idx1, 60 , stdin);
int g=0;
while (g <n_p)
{
g=g+1;
if(strcmp (x1[g].array, idx1)==0 && wrong == false ){
x1[g].idx += idx2;
similar = true;
i1=i1-1;
}
}
if ((similar == false|| n_p == 0) && wrong == false)
{
x1[i1].idx = idx2;
strcpy(x1[i1].array, idx1);
n_p++;
}
similar = false;
}
int i=0;
while(i < n_p-1)
{
i=i+1;
int k=0;
while(k < n_p - i-1)
{
k=k+1;
if (x1[k].idx < x1[k+1].idx)
{
int sidorenko = x1[k+1].idx;
char tmp_name[60];
strcpy(tmp_name, x1[k+1].array);
x1[k+1].idx = x1[k].idx;
strcpy(x1[k+1].array, x1[k].array);
x1[k].idx = sidorenko;
strcpy(x1[k].array, tmp_name);
}
}
}
int i2=0;
while(i2 <n_p)
{
i2=i2+1;
int dima=i2;
while (dima < n_p)
{
dima=dima+1;
if (x1[i].idx == x1[dima].idx)
{
if(x1[i].array[1] > x1[dima].array[1]){
int sidorenko = x1[i].idx;
char tmp_name[60];
strcpy(tmp_name, x1[i].array);
x1[i].idx = x1[dima].idx;
strcpy(x1[i].array, x1[dima].array);
x1[dima].idx = sidorenko;
strcpy(x1[dima].array, tmp_name);
}
if(x1[i].array[1] == x1[dima].array[1])
{
if(x1[i].array[2] > x1[dima].array[2]){
int sidorenko = x1[i].idx;
char tmp_name[60];
strcpy(tmp_name, x1[i].array);
x1[i].idx = x1[dima].idx;
strcpy(x1[i].array, x1[dima].array);
x1[dima].idx = sidorenko;
strcpy(x1[dima].array, tmp_name);
}
}
}
}
}
printf("Vysledky:\n");
int i3=0;
while (i3 < n_p)
{
i3=i3+1;
printf("%d", x1[i].idx);
printf("%s", x1[i].array);
}
return 0;
}