Algorithm


Problem Name: beecrowd | 2708

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2708

Tourists in the Huacachina Park

 

By André Marcos Silva BR Brazil

Timelimit: 1

The municipal tourism agency of the city of Ica in Peru has set up a checkpoint for adventure jeeps that ascend to the dunes of Hucachina Park. As during the day, there are several off-roads that go up and down the national park, and tourists do not always use the same transportation for the round trip, the city hall needed to have better control and security over the flow of visitors in the park. Develop a program that receives as input if a jeep is entering or returning from the park and the amount of tourists this vehicle is transporting. At the end of the shift, the program must indicate how many vehicles and tourists are still missing from the adventure.

 

Input

 

The program must receive successive input pairs. Each pair should indicate the jeep's movement and the amount of tourists it is carrying. The first entry should be "SALIDA" or "VUELTA". "SALIDA" should indicate that the jeep is leaving the center and entering the park; and "VUELTA" that the Jeep is returning from the ride. Immediately following, the program receives an integer T (where, 0 <= T <=20) indicating the amount of tourists being transported by the jeep. The string "ABEND" should be the end-of-processing indicator.

 

Output

 

As a goal the program must present two exits, one in each line: the amount of tourists and the amount of jeeps that still need to return from the park.

 

 

 

Input Samples Output Samples

SALIDA 10
SALIDA 12
SALIDA 10
VUELTA 20
ABEND

12
2

 

 

 

SALIDA 15
SALIDA 20
VUELTA 15
VUELTA 15
SALIDA 0
VUELTA 0
ABEND

5
0

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
#include <string.h>

struct s
{
    char str[10];
    int n;
};

int main(void)

{
    int i, j, sum, in=0, out=0, pin=0, pout=0;
    struct s x;

    while (1)
    {
        scanf("%s", x.str);

        if (strcmp(x.str, "ABEND")==0)
            break;

        scanf("%i", &x.n);

        if (strcmp(x.str, "SALIDA")==0)
        {
            ++in;
            pin+=x.n;
        }

        else if (strcmp(x.str, "VUELTA")==0)
        {
            ++out;
            pout+=x.n;
        }
    }

    printf("%i\n%i\n", pin-pout, in-out);

    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
SALIDA 10 SALIDA 12 SALIDA 10 VUELTA 20 ABEND

Output

x
+
cmd
12 2

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<string>
#include<list>


using namespace std;


#define ll long long
#define input scanf
#define output printf 
#define Loop while
#define echo cout
#define ret return
#define MAX 999999999999999999
#define MIN 0
#define PI 3.1415

bool isPrime(int x);
void sieve();
string toBinary(int n);
bool findingSubString(string a,string b);
vector<int> a(32);
int main(int argc, char** argv) {
	
	//freopen("c.txt","w",stdout);
	string str;
	int a;
	int sum=0;
	int out=0;
	while(cin >> str&&str[0]!='A')
	{
		cin >> a;
		if(str[0]=='S')
		{
			out++;
			sum+=a;
		}
		else
		{
			out--;
			sum-=a;
		}
	}
	printf("%d\n%d\n",sum,out);
	ret 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
SALIDA 10 SALIDA 12 SALIDA 10 VUELTA 20 ABEND

Output

x
+
cmd
12 2

#3 Code Example with Python Programming

Code - Python Programming


turistas = 0
jipes = 0
while True:
    entrada = input().split()
    if entrada[0] == 'ABEND':
        break
    if entrada[0] == 'SALIDA':
        jipes += 1
        turistas += int(entrada[1])
    else:
        jipes -= 1
        turistas -= int(entrada[1])

print(turistas)
print(jipes)
Copy The Code & Try With Live Editor

Input

x
+
cmd
SALIDA 10 SALIDA 12 SALIDA 10 VUELTA 20 ABEND

Output

x
+
cmd
12 2

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("node:fs")
const input = readFileSync("/dev/stdin", "utf8").split(/\s+/)

outer:
for (let index = 0, s = 0, j = 0; index  <  input.length; index += 2) {
	switch (input[index]) {
		case "SALIDA":
			s += Number.parseInt(input[index + 1], 10)
			j++
			break
		case "VUELTA":
			s -= Number.parseInt(input[index + 1], 10)
			j--
			break
		case "ABEND":
			console.log("%d\n%d", s, j)
			break outer
	}
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
SALIDA 10 SALIDA 12 SALIDA 10 VUELTA 20 ABEND

Output

x
+
cmd
12 2
Advertisements

Demonstration


Previous
#2702 Beecrowd Online Judge Solution 2702 Hard Choice Solution in C, C++, Java, Js and Python
Next
#2709 Beecrowd Online Judge Solution 2709 The Coins of Robbie Solution in C, C++, Java, Js and Python