URI Online Judge Solution 1061 Event Time – Solution in C, C++, Java, Python and C#

URI Online Judge Solution 1061 Event Time | Beginner
URI Problem Link – https://www.urionlinejudge.com.br/judge/en/problems/view/1061

Problem Name: 1061 Event Time soluton
Problem Number : URI – 1061 Event Time code
Online Judge : URI Online Judge Solution
Category: Beginner
Solution Language : C,C plus plus, java, python, c#(c sharp)
URI 1061 problem screenshot:

URI Online Judge Solution 1061 Event Time - Solution in C, C++, Java, Python and C#

URI 1061 Event Time Code in C / URI 1061 solution in C:

/**
* Problem No: URI Online Judge Problem 1061
* Solution in C language
* Author: Maniruzzaman Akash
**/
#include <stdio.h>
int main()
{
char a[4], b[2],c[2],d[2],e[2],f[4];
int i,j,k,l,m,n,p,q,r,s,t,u,v,w,x,y,z,h[5];
scanf("%s%d", a,&i);
scanf("%d%s%d%s%d", &j,&b,&k,&c,&l);
scanf("%s%d", &f,&p);
scanf("%d%s%d%s%d", &q, &d,&r,&e,&s);
m=60-l+s;
n=(60-k-1+r)*60;
t=(24-1-j+q)*3600;
u=(p-i-1)*86400;
v=m+n+t+u;

h[0]=v/86400;
printf("%d dia(s)n", h[0]);

h[0]=v%86400;
h[1]=h[0]/3600;
printf("%d hora(s)n", h[1]);

h[1]=h[0]%3600;
h[2]=h[1]/60;
printf("%d minuto(s)n", h[2]);

h[2]=h[1]%60;
printf("%d segundo(s)n", h[2]);
return 0;
}

URI 1061 Event Time Code in C++ / URI 1061 solution in CPP:


#include <iostream>
using namespace std;

int main()
{
string trash;
int dia_i, dia_f, hora_i, hora_f, minuto_i, minuto_f, segundo_i, segundo_f;
int ctr_d = 0, ctr_h = 0, ctr_m = 0, ctr_s = 0;
bool ver_h = false, ver_m = false, ver_s = false;

cin >> trash >> dia_i;
cin >> hora_i >> trash >> minuto_i >> trash >> segundo_i;
cin >> trash >> dia_f;
cin >> hora_f >> trash >> minuto_f >> trash >> segundo_f;

if(hora_i > hora_f)
ver_h = true;

if(minuto_i > minuto_f)
ver_m = true;

if(segundo_i > segundo_f)
ver_s = true;

while(dia_i != dia_f)
{
ctr_d++;
dia_i++;
}

while(hora_i != hora_f)
{
ctr_h++;
hora_i++;
if(hora_i == 25)
hora_i = 1;
}

while(minuto_i != minuto_f)
{
ctr_m++;
minuto_i++;
if(minuto_i == 61)
minuto_i = 1;
}

while(segundo_i != segundo_f)
{
ctr_s++;
segundo_i++;
if(segundo_i == 61)
segundo_i = 1;
}

if(ver_h == true)
ctr_d--;

if(ver_m == true)
ctr_h--;

if(ver_s == true)
ctr_m--;

cout << ctr_d << " dia(s)" << endl;
cout << ctr_h << " hora(s)" << endl;
cout << ctr_m << " minuto(s)" << endl;
cout << ctr_s << " segundo(s)" << endl;

return 0;
}

URI 1061 Event Time Code in java/ URI 1061 solution in Java:

import java.io.IOException;
import java.util.Scanner;

public class
Main {

public static
void main(String[] args) throws IOException {


Scanner sc =new Scanner(System.in);
String string;
int
day_i, day_f, hour_i, hour_f, minute_i, minute_f, second_i, second_f;
int
day = 0, hour = 0, minute = 0, second = 0;
boolean bool_h = false, bool_m = false, bool_s = false;

//----------------------
string =sc.next();
day_i =sc.nextInt();
//----------------------
hour_i =sc.nextInt();
string =sc.next();
minute_i =sc.nextInt();
string =sc.next();
second_i =sc.nextInt();
//----------------------
string =sc.next();
day_f =sc.nextInt();
//----------------------
hour_f =sc.nextInt();
string =sc.next();
minute_f =sc.nextInt();
string =sc.next();
second_f =sc.nextInt();
//----------------------

if
(hour_i > hour_f)
bool_h = true;

if
(minute_i > minute_f)
bool_m = true;

if
(second_i > second_f)
bool_s = true;

while
(day_i != day_f)
{

day++;
day_i++;
}


while
(hour_i != hour_f)
{

hour++;
hour_i++;
if
(hour_i == 25)
hour_i = 1;
}


while
(minute_i != minute_f)
{

minute++;
minute_i++;
if
(minute_i == 61)
minute_i = 1;
}


while
(second_i != second_f)
{

second++;
second_i++;
if
(second_i == 61)
second_i = 1;
}


if
(bool_h == true)
day--;

if
(bool_m == true)
hour--;

if
(bool_s == true)
minute--;

System.out.print(day+" dia(s)n");
System.out.print(hour+" hora(s)n");
System.out.print(minute+" minuto(s)n");
System.out.print(second+" segundo(s)n");

}

}

URI 1061 Event Time Code in Python / URI 1061 solution in Python:

URI Solution 1061 Event Time Code / URI 1061 solution in  C# (C Sharp):

Demonstration:

We just show the procedure of the URI 1061 problem in C language,

First take the necessary input as given format in these lines,

    char a[4], b[2],c[2],d[2],e[2],f[4];
int i,j,k,l,m,n,p,q,r,s,t,u,v,w,x,y,z,h[5];
scanf("%s%d", a,&i);
scanf("%d%s%d%s%d", &j,&b,&k,&c,&l);
scanf("%s%d", &f,&p);
scanf("%d%s%d%s%d", &q, &d,&r,&e,&s);

Then,
We need to find the difference between from one time to another.

Now come to logic –
To convert day to second we need to multiply it

1 day = 24 hour * 60 minutes * 60 seconds = 86,400 seconds
1 hour = 60 minutes * 60 seconds = 3600 seconds
1 minute = 60 seconds

1 second = 1 second




First, change every variable or number to seconds and add them like this, Total second in first is:

    m=60-l+s;
n=(60-k-1+r)*60;
t=(24-1-j+q)*3600;
u=(p-i-1)*86400;
v=m+n+t+u;

Then just find the day, hour, minute and second just using this formula or time calculations logic.

    h[0]=v/86400;
printf("%d dia(s)n", h[0]);

h[0]=v%86400;
h[1]=h[0]/3600;
printf("%d hora(s)n", h[1]);

h[1]=h[0]%3600;
h[2]=h[1]/60;
printf("%d minuto(s)n", h[2]);

h[2]=h[1]%60;
printf("%d segundo(s)n", h[2]);


Divide the total time by 86400 and its divide result is day as usual but we need the hour.
So, its reminder(%) time is in the second time and so again divide it by 3600 and get the hour time.
Got clear may be.

And by same procedure, we find out the minute time and then second time.

Tags: URI Online Judge Solution, URI OJ Solution list, URI Problems Solution, URI solver, URI all problem solution list, URI 1061 Event Time  code in C, URI 1061 code in C++, URI Event time solution in C, URI solution, URI 1061 Event Time solution in C,URI 1061 solution in C++-CPP,URI 1061 solution in C# (C sharp),URI 1061 Event Time solution in Java,URI 1061 Event Time solution in Python,

By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS

Leave a Reply

Your email address will not be published. Required fields are marked *