Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Dasproc C - 2019
- William Handi Wijaya
- 0087
- Program untuk mengurutkan rank nilai dari yang terbesar
- dengan urutan prioritas desain > gameplay > ui > nama.
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdbool.h>
- typedef struct
- {
- char nama[11];
- int desain;
- int gameplay;
- int ui;
- } apps;
- apps *data = NULL;
- bool swapped;
- int t;
- void sort(char prompt[9]);
- void swap(int j);
- int main(void)
- {
- // Input banyak aplikasi
- scanf("%d", &t);
- // Input keterangan aplikasi
- data = (apps*) malloc(sizeof(apps) * t);
- for (int i = 0; i < t; i++)
- {
- scanf("%s %d %d %d", data[i].nama, &data[i].desain, &data[i].gameplay, &data[i].ui);
- }
- // Sort
- sort((char*) "desain");
- sort((char*) "gameplay");
- sort((char*) "UI");
- sort((char*) "nama");
- // Print
- for (int i = 0; i < t; i++)
- {
- printf("%s\n", data[i].nama);
- }
- free(data);
- return 0;
- }
- void sort(char prompt[9])
- {
- for (int i = 0; i < t-1; i++)
- {
- swapped = false;
- for (int j = 0; j < t-i-1; j++)
- {
- if (strncmp(prompt, "desain", 1) == 0)
- {
- if (data[j].desain < data[j + 1].desain)
- {
- swap(j);
- }
- }
- else if (strncmp(prompt, "gameplay", 1) == 0)
- {
- if (data[j].desain == data[j + 1].desain && data[j].gameplay < data[j + 1].gameplay)
- {
- swap(j);
- }
- }
- else if (strncmp(prompt, "UI", 1) == 0)
- {
- if (data[j].desain == data[j + 1].desain && data[j].gameplay == data[j + 1].gameplay && data[j].ui < data[j + 1].ui)
- {
- swap(j);
- }
- }
- else
- {
- if (data[j].desain == data[j + 1].desain && data[j].gameplay == data[j + 1].gameplay && data[j].ui == data[j + 1].ui && strcmp(data[j].nama, data[j + 1].nama) > 0)
- {
- swap(j);
- }
- }
- }
- if (swapped == false) break;
- }
- }
- void swap(int j)
- {
- apps tmp = data[j];
- data[j] = data[j + 1];
- data[j + 1] = tmp;
- swapped = true;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment