Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- struct GraphicsCard
- {
- char Brand[20];
- char Model[20];
- int Price;
- int RAM;
- int Speed;
- GraphicsCard()
- {
- strcpy(Brand, "");
- strcpy(Model, "");
- Price = 0;
- RAM = 0;
- Speed = 0;
- }
- GraphicsCard(char _Brand[], char _Model[], int _Price, int _RAM, int _Speed)
- {
- strcpy(Brand, _Brand);
- strcpy(Model, _Model);
- Price = _Price;
- RAM = _RAM;
- Speed = _Speed;
- }
- };
- void sort_GraphicsCard_speed(struct GraphicsCard* gpu[], int n)
- {
- struct GraphicsCard now, next;
- struct GraphicsCard* temp;
- int i, j;
- for(i=0; i<n-1; i++)
- {
- for(j=0; j<n-1; j++)
- {
- now = *gpu[j];
- next = *gpu[j+1];
- if(now.Speed < next.Speed)
- {
- temp = gpu[j];
- gpu[j] = gpu[j+1];
- gpu[j+1] = temp;
- }
- }
- }
- }
- int main()
- {
- char Brand[20], Model[20];
- int Price, RAM, Speed, i, n;
- struct GraphicsCard* gpu[100];
- scanf("%d", &n);
- for(i=0; i<n; i++)
- {
- scanf("%s %s %d %d %d", &Brand, &Model, &Price, &RAM, &Speed);
- gpu[i] = new GraphicsCard(Brand, Model, Price, RAM, Speed);
- }
- sort_GraphicsCard_speed(gpu, n);
- for(i=0; i<n; i++)
- {
- struct GraphicsCard temp = *gpu[i];
- printf("%s %s %d %d %d\n", temp.Brand, temp.Model, temp.Price, temp.RAM, temp.Speed);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement