juanjo12x

Live_Archive_6627

Oct 3rd, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. bool isLeap(int anho){
  7.     if(anho%4==0){
  8.         if(anho%100==0 && anho%400 != 0){
  9.             return false;
  10.         }else{
  11.             return true;
  12.         }
  13.     }
  14.     return false;
  15. }
  16.  
  17. int main(){
  18.      
  19.     int anho, mes, dia;
  20.     while(scanf("%d-%d-%d",&anho,&mes,&dia)!= EOF){
  21.         int cuenta = 11;
  22.         for(int i = 1600; i < anho;i+=100){
  23.             if(!isLeap(i)){
  24.                 cuenta++;
  25.             }
  26.         }
  27.        // cout << cuenta<<endl;
  28.         if(!isLeap(anho) && anho % 100 == 0){
  29.             if(mes >= 3 ){
  30.                 cuenta++;
  31.             }
  32.             if( (dia==29 && mes ==2)){
  33.                 dia = 1;
  34.                 mes = 3;
  35.             }
  36.         }
  37.          
  38.          
  39.          
  40.         int meses[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  41.         int mesesb[] = {31,29,31,30,31,30,31,31,30,31,30,31};
  42.        // cout << cuenta << endl;
  43.         for(int j = 0; j < cuenta; j++){
  44.             if(isLeap(anho)){
  45.                 if(dia+1 > mesesb[mes-1]){
  46.                     dia=1;
  47.                      if(mes+1>12){
  48.                         mes=1;
  49.                         anho++;
  50.                          
  51.                     }else{
  52.                         mes++;
  53.                     }
  54.                 }else{
  55.                     dia++;                    
  56.                      
  57.                 }
  58.                  
  59.             }else{
  60.                 if(dia+1 > meses[mes-1]){
  61.                     dia=1;
  62.                      if(mes+1>12){
  63.                         mes=1;
  64.                         anho++;
  65.                          
  66.                     }else{
  67.                         mes++;
  68.                     }
  69.                 }else{
  70.                     dia++;                    
  71.                      
  72.                 }
  73.             }  
  74.        
  75.         }  
  76.          
  77.         cout << anho <<"-";
  78.         if(mes <=9){
  79.             cout << "0"<<mes<<"-";
  80.         }else{
  81.             cout << mes<<"-";
  82.         }
  83.         if(dia <= 9){
  84.             cout << "0"<<dia<<endl;
  85.         }else{
  86.             cout << dia << endl;
  87.         }
  88.          
  89.          
  90.          
  91.      
  92.     }
  93.     return 0;
  94.      
  95.  
  96. }
Add Comment
Please, Sign In to add comment