Advertisement
kokusz19

2017.05.30.Benzinkut

Jun 5th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://progcont.hu/progcont/100220/exercises.html?pid=201110
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6.  
  7. typedef struct SZAMOK{ //szamok struct
  8. int szam;
  9. int oszto;
  10. }SZAMOK;
  11.  
  12. char sor[100];
  13. SZAMOK tomb[100];
  14.  
  15.  
  16. int hasonlito(const SZAMOK *a, const SZAMOK *b) //qsort hasonlitoja #1 oszto szerint, 2# melyik a nagyobb
  17. {
  18. if(a->oszto < b->oszto)
  19. return -1;
  20. if(a->oszto > b->oszto)
  21. return 1;
  22. if(a->oszto == b->oszto)
  23. {
  24. if(a->szam > b->szam)
  25. return 1;
  26. if(a->szam < b->szam)
  27. return -1;
  28. if(a->szam == b->szam)
  29. return 0;
  30. }
  31. }
  32.  
  33. int main()
  34. {
  35. int i, j, index=0, vesszo = 0;
  36. int elsoszam, nemmegy = 1;
  37. while(fgets(sor,100,stdin) != NULL)
  38. {
  39.  
  40. for(i=0;i<strlen(sor);i++) //sor elemeinek "tomb" tombbe helyezese
  41. {
  42. switch(sor[i])
  43. {
  44. case '0' : tomb[index].szam = (tomb[index].szam*10) + 0; break;
  45. case '1' : tomb[index].szam = (tomb[index].szam*10) + 1; break;
  46. case '2' : tomb[index].szam = (tomb[index].szam*10) + 2; break;
  47. case '3' : tomb[index].szam = (tomb[index].szam*10) + 3; break;
  48. case '4' : tomb[index].szam = (tomb[index].szam*10) + 4; break;
  49. case '5' : tomb[index].szam = (tomb[index].szam*10) + 5; break;
  50. case '6' : tomb[index].szam = (tomb[index].szam*10) + 6; break;
  51. case '7' : tomb[index].szam = (tomb[index].szam*10) + 7; break;
  52. case '8' : tomb[index].szam = (tomb[index].szam*10) + 8; break;
  53. case '9' : tomb[index].szam = (tomb[index].szam*10) + 9; break;
  54. case ' ' : index++; break;
  55. case '\0' : index++; break;
  56. case '\n' : index++; break;
  57. }
  58. if(index == tomb[0].szam+1) break;
  59.  
  60. }
  61.  
  62. for(i=0;i<index;i++) //osztok szamlalasa & elso elem meghatarozasa
  63. {
  64. elsoszam = tomb[0].szam;
  65. tomb[i].oszto = 0;
  66. for(j=1;j<=tomb[i].szam;j++)
  67. {
  68. if(tomb[i].szam % j == 0 && j % 2 == 0)
  69. {
  70. tomb[i].oszto++;
  71. }
  72. }
  73. }
  74.  
  75. qsort(tomb, index, sizeof(SZAMOK), hasonlito); //qsort meghivasa
  76.  
  77. for(i=0;i<index;i++) //kiiratas, kiveve az 1. elemet
  78. {
  79. if(tomb[i].szam == elsoszam && nemmegy == 1)
  80. {
  81. nemmegy = 0;
  82. i++;
  83. }
  84. printf("%d ", tomb[i].szam);
  85. }
  86.  
  87. printf("\n");
  88. nemmegy = 1;
  89. memset(tomb,0,100);
  90. index = 0;
  91. }
  92. return EXIT_SUCCESS;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement