lunes, 24 de octubre de 2011

10683 - The decadary watch, uva

#include<iostream>
#include<cstring>
#include<cstdio>
#define db(a) cout << #a << " = " << a << endl;
#define db2(a, b) cout << #a << " = " << a << " -- "<< #b << " = " << b << endl;
#define foreach(it, l) for(typeof(l.begin()) it = l.begin(); it != l.end(); it++)
using namespace std;
int main(){
	string t;
	int HH, MM, SS, CC, g;
	while(cin >> t){
		HH = (t[0] - 48)*10 + (t[1] - 48);
		MM = (t[2] - 48)*10 + (t[3] - 48);
		SS = (t[4] - 48)*10 + (t[5] - 48);
		CC = (t[6] - 48)*10 + (t[7] - 48);
		g = HH * 3600 + MM * 60 + SS;
		g *= 100;
		g += CC;
		g = (125 * g) / 108;
		printf("%07d\n", g);
	}
	return 0;
}

2 comentarios:

  1. Respuestas
    1. sorry for the late response, well
      the relation between sexagesimal and decimal systems here
      can be expressed as S/24hours = C/10hours
      but 24 has 24*60 minutes and 24*60*60 seconds
      likewise 10 hours has 10*100 minutes and 10*100*100 seconds

      so the relation looks like this:
      S / 24*60*60 secs= C / 10*100*100 secs
      reducing
      S / 108 = C / 125 or C = 125 * S / 108
      then as the statement says
      "For each given traditional time, the output will echo a line with the corresponding decimal time, rounded by truncation, in the format HMMSSCC"
      then we have decimal miliseconds after the conversion,
      so we have to truncate, but that's done when we divide automatically
      so we have to insure it has the format "HMMSSCC" thats why
      I'll add '0' to the right if the time is to low in the conversion meaning maybe
      there is no hours just minutes, that's why I add %07d

      Eliminar