Rezultati

Up. imeNalogaJezikRezultatČas oddaje
javanskivaljar-2018 Podnapisi C++ 100/100OK 10. maj '18 @ 19:30

Test Točke Porabljen spomin Porabljen čas Status
#1 7/7 3,340 MiB 0,004 s OK
#2 7/7 3,457 MiB 0,009 s OK
#3 7/7 3,070 MiB 0,000 s OK
#4 7/7 3,063 MiB 0,019 s OK
#5 7/7 3,070 MiB 0,000 s OK
#6 7/7 3,137 MiB 0,004 s OK
#7 7/7 3,063 MiB 0,000 s OK
#8 7/7 3,133 MiB 0,004 s OK
#9 7/7 3,070 MiB 0,004 s OK
#10 7/7 3,859 MiB 0,020 s OK
#11 7/7 3,137 MiB 0,000 s OK
#12 7/7 3,258 MiB 0,000 s OK
#13 8/8 3,391 MiB 0,009 s OK
#14 8/8 3,137 MiB 0,004 s OK

Ocenjevani program (Podnapisi.cpp):
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char** split(char* TimeStamp);
using namespace std;
char** split_extra(char* TimeStamp);
char* add_leading_zeros(int number, int length);
int split_shift_int[4];
int split_milis;
int split_secs;
int split_mins;
int split_hours;
int toInt(char* number);
void readindex();
char* IncrementTimeStamp(char* TimeStamp);
char** readtimestamp();
void readtext();
int main()
{
	char* shift = new char[20];
	cin >> shift;
	cin >> shift;
	char** split_shift = split(shift);
	split_shift_int[0] = toInt(split_shift[0]);
	split_shift_int[1] = toInt(split_shift[1]);
	split_shift_int[2] = toInt(split_shift[2]);
	split_shift_int[3] = toInt(split_shift[3]);
	split_milis = split_shift_int[3];
	split_secs = split_shift_int[2];
	split_mins = split_shift_int[1];
	split_hours = split_shift_int[0];

	char* line = new char[300];
	char c;
	int line_index = 0;
	getchar();
	while(1)
	{	
		readindex();
		char** timestampsss = readtimestamp();
		char* newstarttime = IncrementTimeStamp(timestampsss[0]);
		char* newendtime = IncrementTimeStamp(timestampsss[1]);
		printf("%s --> %s\n", newstarttime, newendtime);
		readtext();

	}
}
void readtext()
{
char c;
	int doublenewline = 0;
	while(doublenewline != 2)
	{	
		c = getchar();
		if(c == EOF)
		{
			exit(0);
		}
		if(c == '\n')
		{
			doublenewline++;
		}
		else
		{
			doublenewline = 0;
		}
		if(doublenewline != 2)
		{
			putchar(c);
		}
		else{
			printf("\n");
		}
	}
}
char** readtimestamp()
{
	char** timestampsss = new char*[2];
	timestampsss[0] = new char[13];
	timestampsss[0][12] = 0;
	timestampsss[1] = new char[13];
	timestampsss[1][12] = 0;
	int i = 0;
	int ind = 0;
	char c;
	while((c = getchar()) != '\n')
	{	
		if(c == ' ' || c == '-' || c == '>')
		{
			ind = 1;
			i = 0;
		}
		else
		{
			timestampsss[ind][i] = c;
			i++;
		}
	}
	return timestampsss;
}
void readindex(){
	char c;
	while((c = getchar()) != '\n')
	{	
		putchar(c);
	}
	printf("\n");
}
int toInt(char* number)
{
	int int_number = 0;
	int number_length = strlen(number);
	int PowerOfTen = 1;
	for(int i = number_length - 1; i>=0; i--)
	{
		int_number += ((number[i] - '0') * PowerOfTen);
		PowerOfTen *= 10;
	}

	return int_number;
}
char* IncrementTimeStamp(char* TimeStamp)
{
	char** TimeStampSplit = split(TimeStamp);
	delete[] TimeStamp;

	int Milis = toInt(TimeStampSplit[3]);
int Sec = toInt(TimeStampSplit[2]);
int Mins = toInt(TimeStampSplit[1]);
int Hours = toInt(TimeStampSplit[0]);

	int NewMilis = (split_milis + Milis) % 1000;
        int NewMilisCarry = (split_milis + Milis) / 1000;

        int NewSec = ((split_secs + Sec + NewMilisCarry) % 60);
        int NewSecCarry = ((split_secs + Sec + NewMilisCarry) / 60);

        int NewMins = ((split_mins + Mins + NewSecCarry) % 60);
        int NewMinsCarry = ((split_mins + Mins + NewSecCarry) / 60);

        int NewHours = ((split_hours + Hours + NewMinsCarry) % 24);
        int NewHoursCarry = ((split_hours + Hours + NewMinsCarry) / 24);
	
	char* milis_string = add_leading_zeros(NewMilis, 3);
	char* secs_string = add_leading_zeros(NewSec, 2);
	char* mins_string = add_leading_zeros(NewMins, 2);
	char* hours_string = add_leading_zeros(NewHours, 2);

	char* final_string = new char[13];
	final_string[12] = 0;

	strcpy(final_string, hours_string);
	strcat(final_string, ":");
	strcat(final_string, mins_string);
strcat(final_string, ":");
	strcat(final_string, secs_string);
strcat(final_string, ",");
	strcat(final_string, milis_string);
	
	delete[] hours_string;
delete[] mins_string;
delete[] secs_string;
delete[] milis_string;
	return final_string;
}
char** split(char* TimeStamp)
{
	char** time = new char*[4];
	time[0] = new char[3];
	time[1] = new char[3];
	time[2] = new char[3];
	time[3] = new char[4];

	for(int i = 0; i < 2; i++)
	{
		time[0][i] = TimeStamp[i];
	}
	time[0][2] = 0;
	for(int i = 3; i < 5; i++)
	{
		time[1][i - 3] = TimeStamp[i];
	}
	time[1][2] = 0;
for(int i = 6; i < 8; i++)
	{
		time[2][i - 6] = TimeStamp[i];
	}
	time[2][2] = 0;
for(int i = 9; i < 12; i++)
	{
		time[3][i - 9] = TimeStamp[i];
	}
	time[3][3] = 0;

	return time;
}
char** split_extra(char* TimeStamp)
{
	char** time = new char*[4];
	time[0] = new char[3];
	time[1] = new char[3];
	time[2] = new char[3];
	time[3] = new char[4];
	TimeStamp += 7;
	for(int i = 0; i < 2; i++)
	{
		time[0][i] = TimeStamp[i];
	}
	time[0][2] = 0;
	for(int i = 3; i < 5; i++)
	{
		time[1][i - 3] = TimeStamp[i];
	}
	time[1][2] = 0;
for(int i = 6; i < 8; i++)
	{
		time[2][i - 6] = TimeStamp[i];
	}
	time[2][2] = 0;
for(int i = 9; i < 11; i++)
	{
		time[0][i - 9] = TimeStamp[i];
	}
	time[3][3] = 0;
	
	return time;
}
char* add_leading_zeros(int number, int length)
{
	int number_length = 0;
	int number_copy = number;
	while(number != 0)
	{
		number_length++;
		number /= 10;
	}
	char* string_number = new char[length + 1];
	string_number[length] = '\0';
	number = number_copy;
	int index = length - 1;
	while(number != 0)
	{
		string_number[index] = (number % 10) + '0';
		index--;
		number /= 10;
	}
	while(index != -1)
	{
		string_number[index] = '0';
		index--;
	}
	return string_number;
}