Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Lógica: Recebo n, k e uma matriz[n][COLUNAS] de strings
- Coloco as strings da matriz[n][COLUNAS] em ordem alfabetica
- pego a string matriz[k-1] e imprimo*/
- #include <stdio.h>
- #include <string.h>
- #define LINHAS 100 //até 100 nomes, como descrito no exercicio
- #define COLUNAS 21 //nome de até 20 caractéres, como descrito no exercicio
- void RecebeDados(int *n, int *k, char alunos[][COLUNAS]);
- void Organiza(int n, int k, char alunos[][COLUNAS]);
- int main(){
- int n, k;
- char alunos[LINHAS][COLUNAS];
- RecebeDados(&n,&k,alunos);
- Organiza(n, k, alunos);
- printf("%s\n", alunos[k-1]);
- return 0;
- }
- void RecebeDados(int *n, int *k, char alunos[][COLUNAS]){
- scanf("%d %d", n, k);
- getchar();
- for(int i=0; i<*n; i++) gets(alunos[i]);
- }
- void Organiza(int n, int k, char alunos[][COLUNAS]){
- char aux[COLUNAS];
- for(int i=0; i<n-1; i++){
- for(int j=i+1; j<n; j++){
- if(strcmp(alunos[i], alunos[j]) > 0){
- strcpy(aux, alunos[i]);
- strcpy(alunos[i], alunos[j]);
- strcpy(alunos[j], aux);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement