Last active
March 26, 2018 08:25
-
-
Save jwon0615/0db7e42760e1a4f8994fcbc38fb78baa to your computer and use it in GitHub Desktop.
2_codeup_연습문제_구조체
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
typedef struct { | |
int x, y; | |
}point; | |
int main(){ | |
point p1, p2; | |
double i; | |
scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y); | |
i=sqrt( pow((p1.x-p2.x),2) + pow((p1.y-p2.y),2)); | |
printf("%.2f", i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <malloc.h> | |
typedef struct { | |
int x, y; | |
}point; | |
int main(){ | |
int n; | |
double sum=0; | |
scanf("%d", &n); | |
point *p=(point *)malloc(sizeof(point)); | |
//point p[101]; //point p[n]; | |
scanf("%d %d", &p[0].x, &p[0].y); | |
for(int i=1; i<n; i++) { | |
scanf("%d %d", &p[i].x, &p[i].y); | |
sum+=sqrt( pow((p[i-1].x - p[i].x),2) + pow((p[i-1].y - p[i].y),2)); | |
} | |
printf("%.2f", sum); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <malloc.h> | |
typedef struct { | |
char name[10]; | |
int score; | |
}student; | |
void swaps( student &a, student &b){ | |
student tmp; | |
tmp=a; | |
a=b; | |
b=tmp; | |
} | |
int main() { | |
int n,m; | |
scanf("%d %d",&n,&m); | |
student *st=(student *)malloc(sizeof(student)*n); | |
//student st[101]; //student st[n]; | |
for(int i=0;i<n;i++) | |
scanf("%s %d", st[i].name, &st[i].score); | |
for(int i=0; i<n-1; i++) { | |
for(int j=0;j<n-1-i;j++) { | |
if(st[j].score<st[j+1].score) { | |
swaps(st[j], st[j+1]); | |
} | |
} | |
} | |
for(int i=0;i<m;i++) | |
printf("%s\n",st[i].name); | |
//for(int i=0; i<n;i++) | |
// printf("%s %d\n", st[i].name, st[i].score); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<malloc.h> | |
typedef struct | |
{ | |
char name[10]; | |
int s1; | |
int s2; | |
int s3; | |
}student; | |
int main() | |
{ | |
int n; | |
int max=-999, loc = 0, rank2=1,rank3=1; | |
scanf("%d",&n); | |
student *p=(student *)malloc(sizeof(student)*n); | |
//student p[n]; | |
for(int i=0;i<n;++i) | |
{ | |
scanf("%s %d %d %d",p[i].name,&p[i].s1,&p[i].s2,&p[i].s3); | |
if(p[i].s1>max) | |
{ | |
max=p[i].s1; | |
loc=i; | |
} | |
} | |
for(int i=0;i<n;++i) | |
{ | |
if(p[i].s2>p[loc].s2) rank2++; | |
if(p[i].s3>p[loc].s3) rank3++; | |
} | |
printf("%s %d %d",p[loc].name,rank2,rank3); | |
free(p); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment