时间转换

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

 int startime, changertime,t,m,finallytime;

 cin >> startime >> changertime;

 t = startime / 100;

 m = startime % 100;

 if (changertime > 60)

 {

  t += 1;

  changertime -= 60;

  if (m + changertime>60)

  {

   t += 1;

   m=m+changertime -60;

  }

  else

  {

   t = t;

   m += changertime;

  }

 }

 else if (0 <= changertime&&changertime <= 60)

 {

  if (m + changertime>60)

  {

   t += 1;

   m=m+changertime – 60;

  }

  else

  {

   t = t;

   m += changertime;

  }

 }

 else

 {

  if (0 <= m + changertime)

  {

   t = t;

   m = m + changertime;

  }

  else if (-60 <= m + changertime&&m + changertime<0)

  {

   t -= 1;

   m += changertime + 60;

  }

  else

  {

   t = t – abs(changertime)/60;

   if (m – abs(changertime)%60 < 0)

   {

    t = t – 1;

    m = m – abs(changertime) % 60 + 60;

   }

   else

   {

    t = t;

    m = m – abs(changertime) % 60;

   }

  }

 }

 finallytime = t * 100 + m;

 cout <<finallytime << endl;

 return 0;

}

#include <stdio.h>

int main()

{

 int time, min, hour, h, m, temp;

 scanf_s(“%d %d”, &time, &min);

 hour = min / 60;

 min = min % 60;

 h = time / 100;

 m = time % 100;

 temp = (min + m) / 60;

 m = (min + m) % 60;

 h = hour + h + temp;

 if (m<0)

  printf(“%d%d\n”, h – 1, 60 + m);

 else

  printf(“%d%d\n”, h, m);

 return 0;

}

点赞