GatoBooster

MOD 3 Cuest 4 Preg 1

Sep 28th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. //gcc 5.4.0
  2.  
  3. #include  <stdio.h>
  4.  
  5. typedef struct posicion{
  6.     int x;
  7.     int y;
  8.     int menor;
  9. }Pos;
  10.  
  11. int main(void)
  12. {
  13.     //Declaración de Variables
  14.     Pos pos;
  15.     int largo;
  16.    
  17.     scanf("%d",&largo);
  18.    
  19.     //Rellenar el vector
  20.     int vector[largo];
  21.     int i, j, aux;
  22.     for(i = 0; i < largo; i++){
  23.         scanf("%d",&vector[i]);
  24.     }
  25.    
  26.     //Buscar el menor de los datos y la posicion de Y
  27.     pos.menor = vector[largo-1];
  28.     pos.y     = largo-1;
  29.     for(i = largo-1; i >= 0; i--){
  30.         if(pos.menor > vector[i]){
  31.             pos.menor = vector[i];
  32.             pos.y = i;
  33.         }
  34.     }
  35.    
  36.     //Buscar el menor de los datos y la posicion de X
  37.     pos.x = 0;
  38.     for(i = 0; i < largo-1; i++){
  39.         if(pos.menor == vector[i]){
  40.             if(pos.y == i){
  41.                 pos.x = i;
  42.             }else{
  43.                 pos.x = i+1;
  44.             }
  45.         }else{
  46.             break;
  47.         }
  48.     }    
  49.    
  50.     //printf("%d V1  ",vector[0]);printf("%d V2   ",vector[1]);printf("%d V3\n",vector[2]);
  51.    
  52.     for(i = pos.x; i <= pos.y; i++){
  53.         for(j = pos.x; j <= pos.y && i != j; j++){
  54.             if(vector[i] < vector[j]){
  55.                 aux = vector[i];
  56.                 vector[i] = vector[j];
  57.                 vector[j] = aux;
  58.             }
  59.         }    
  60.     }
  61.    
  62.     for(i = 0; i < largo-1; i++){
  63.         if(vector[i] > vector[i+1]){
  64.             break;
  65.         }
  66.     }
  67.    
  68.     //printf("%dL\n",largo);printf("%d V1  ",vector[0]);printf("%d V2   ",vector[1]);printf("%d V3\n",vector[2]);
  69.     //printf("%dMenor\n",pos.menor);printf("%dY\n",pos.y);printf("%dX\n",pos.x);
  70.     //printf("%dI\n",i);
  71.    
  72.     if(largo-1 == i){
  73.         printf("VERDADERO: desde x=%d hasta y=%d.",pos.x+1,pos.y+1);
  74.     }else{
  75.         printf("FALSO.");
  76.     }
  77.    
  78.    
  79.    
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment