Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://progcont.hu/progcont/100220/exercises.html?pid=201110
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- typedef struct SZAMOK{ //szamok struct
- int szam;
- int oszto;
- }SZAMOK;
- char sor[100];
- SZAMOK tomb[100];
- int hasonlito(const SZAMOK *a, const SZAMOK *b) //qsort hasonlitoja #1 oszto szerint, 2# melyik a nagyobb
- {
- if(a->oszto < b->oszto)
- return -1;
- if(a->oszto > b->oszto)
- return 1;
- if(a->oszto == b->oszto)
- {
- if(a->szam > b->szam)
- return 1;
- if(a->szam < b->szam)
- return -1;
- if(a->szam == b->szam)
- return 0;
- }
- }
- int main()
- {
- int i, j, index=0, vesszo = 0;
- int elsoszam, nemmegy = 1;
- while(fgets(sor,100,stdin) != NULL)
- {
- for(i=0;i<strlen(sor);i++) //sor elemeinek "tomb" tombbe helyezese
- {
- switch(sor[i])
- {
- case '0' : tomb[index].szam = (tomb[index].szam*10) + 0; break;
- case '1' : tomb[index].szam = (tomb[index].szam*10) + 1; break;
- case '2' : tomb[index].szam = (tomb[index].szam*10) + 2; break;
- case '3' : tomb[index].szam = (tomb[index].szam*10) + 3; break;
- case '4' : tomb[index].szam = (tomb[index].szam*10) + 4; break;
- case '5' : tomb[index].szam = (tomb[index].szam*10) + 5; break;
- case '6' : tomb[index].szam = (tomb[index].szam*10) + 6; break;
- case '7' : tomb[index].szam = (tomb[index].szam*10) + 7; break;
- case '8' : tomb[index].szam = (tomb[index].szam*10) + 8; break;
- case '9' : tomb[index].szam = (tomb[index].szam*10) + 9; break;
- case ' ' : index++; break;
- case '\0' : index++; break;
- case '\n' : index++; break;
- }
- if(index == tomb[0].szam+1) break;
- }
- for(i=0;i<index;i++) //osztok szamlalasa & elso elem meghatarozasa
- {
- elsoszam = tomb[0].szam;
- tomb[i].oszto = 0;
- for(j=1;j<=tomb[i].szam;j++)
- {
- if(tomb[i].szam % j == 0 && j % 2 == 0)
- {
- tomb[i].oszto++;
- }
- }
- }
- qsort(tomb, index, sizeof(SZAMOK), hasonlito); //qsort meghivasa
- for(i=0;i<index;i++) //kiiratas, kiveve az 1. elemet
- {
- if(tomb[i].szam == elsoszam && nemmegy == 1)
- {
- nemmegy = 0;
- i++;
- }
- printf("%d ", tomb[i].szam);
- }
- printf("\n");
- nemmegy = 1;
- memset(tomb,0,100);
- index = 0;
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement