Coding Exercise – Timus Online Judge – 1409. Two Gangsters, C/C++ solution


1409  Coding Exercise – Timus Online Judge – 1409. Two Gangsters, C/C++ solution algorithms beginner c / c++ code implementation programming languages

This problem is from Timus Online Judge. The original problem description can be found here.

Again, this problem is marked as for ‘High School Pupils’, which means it very easy. However, just try to read through the problem description before looking for answers. This will improve your ability of problem solving/analysis.

The two gangsters shooting from both directions, one from left, the other from the right. They will eventually shoot the same one in the middle. Therefore, the total number of beer cans equal to two numbers (shots by both) minus one.

H H H H (HL) L L L L L

The total number = 5 (H) + 6 (L) – 1 = 10

The questions asks for the cans not shot by each other.

Answer for ‘cans not shot by Harry’ is L – 1, Answer for ‘cans not shot by Larry’ is is H – 1.

The solution is to print L – 1, H – 1 (given numbers minus one, reverse order)

1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;
 
int main()
{
  int a, b;
  cin >> a >> b;
  cout << b - 1 << a - 1;
  return 0;
}
#include <iostream>
using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  cout << b - 1 << a - 1;
  return 0;
}

Or, if you prefer pure C.

1
2
3
4
5
6
7
8
#include <stdio.h>
 
int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d %d", b - 1, a - 1);
    return 0;
}
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d %d", b - 1, a - 1);
    return 0;
}

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
329 words
Last Post: Coding Exercise - Timus Online Judge - 1293. Eniya, C/C++ solution
Next Post: Coding Exercise – Timus Online Judge – 1820. Ural Steaks, C/C++ solution

The Permanent URL is: Coding Exercise – Timus Online Judge – 1409. Two Gangsters, C/C++ solution

One Response

  1. mirajehossain

Leave a Reply