Advertisement
juanjo12x

UVA_12247_Jollo

Jul 24th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #define N 1000000
  14. #define LL unsigned long long
  15. int princess[3];int prince[3]; int tomados[3];
  16. using namespace std;
  17.  
  18. bool notomado(int a){
  19.     for(int i=0;i<3;i++){
  20.         if(a==tomados[i]){
  21.             return false;
  22.         }
  23.     }
  24.     return true;
  25. }
  26. bool test (int a){
  27.     prince[2]=a;int posible=0;int cont;
  28.     int cont1;
  29.     cont1=0;tomados[cont1]=0;tomados[1]=0;tomados[2]=0;
  30.     for (int i=0;i<3;i++){
  31.         cont=0;
  32.         for(int j=0;j<3;j++){
  33.             if((princess[i]>prince[j]) && (notomado(prince[j]))){
  34.                             tomados[cont1]=prince[j];
  35.                             cont1++;
  36.                             cont++;break;
  37.             }
  38.         }
  39.         if(cont>=1) posible++;
  40.     }
  41.     if (posible>=2){
  42.         return false;
  43.     }else{
  44.         return true;
  45.     }
  46.    
  47. }
  48. bool verificar(int i){
  49.     bool temp=true;
  50.     for(int j=0;j<3;j++){
  51.         if(princess[j]==i){
  52.             temp=false;
  53.             break;
  54.         }
  55.     }
  56.     for(int j=0;j<2;j++){
  57.         if(prince[j]==i){
  58.             temp=false;
  59.             break;
  60.         }
  61.     }
  62.     return temp;
  63. }
  64. int main() {
  65.         int a,b,c,d,e;
  66.  int temp,posible,cont,min;bool noesta=false;
  67.  bool verif=false;
  68.  while (cin>>a>>b>>c>>d>>e){
  69.         if(a==0 && b==0 && c==0 && d==0 && e==0) break;
  70.        
  71.         princess[0]=a;princess[1]=b;princess[2]=c;
  72.         prince[0]=d;prince[1]=e;
  73.         /*proceso de ordenamiento*/
  74.         for(int i=1;i<2;i++){
  75.                 for(int j=0;j<2-i;j++){
  76.                         if (prince[j]>prince[j+1]){
  77.                                 temp=prince[j];
  78.                                 prince[j]=prince[j+1];
  79.                                 prince[j+1]=temp;
  80.                         }
  81.                 }
  82.         }
  83.         for(int i=1;i<3;i++){
  84.                 for(int j=0;j<3-i;j++){
  85.                         if (princess[j]>princess[j+1]){
  86.                                 temp=princess[j];
  87.                                 princess[j]=princess[j+1];
  88.                                 princess[j+1]=temp;
  89.                         }
  90.                 }
  91.         }
  92.         /*--------*/
  93.         for(int i=1;i<53;i++){
  94.             noesta=verificar(i);
  95.             if (noesta){
  96.                
  97.                 verif=test(i);
  98.                 if (verif){
  99.                 min=i;
  100.                 break;
  101.             }
  102.             }
  103.            
  104.         }
  105.         if(!verif) printf("-1\n");
  106.         else printf("%d\n",min);
  107.    }
  108.    return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement