Program to Generate Tsunami Report in C, Java and Python
Step-by-step solutions in C, Java and Python for the Tsunami report problem: read three integers, print a numbered report in exact format.
The Tsunami report program is a classic formatted-output problem: read three integers representing casualty counts, then print a labelled, numbered report in a precise format.
It appears regularly in placement online tests and first-year programming lab assignments. The algorithm is three lines of logic. The real test is whether you read the output specification carefully enough to match it character for character, because online judges accept nothing less than an exact match.
What the Problem Asks
A news reporter is covering a tsunami disaster and needs to publish a damage summary. The program accepts three counts (people who died, people who were injured, and people who are safe) and prints them as a structured report.
Input format: Three integers, each on its own line.
- Line 1: number of dead
- Line 2: number of injured
- Line 3: number of safe
Output format: A three-line numbered report followed by a fixed closing message. For inputs 2000, 3000, and 10000, the exact expected output is:
1)Dead : 2000
2)Injured : 3000
3)Safe : 10000
Please help the people who are suffering!!!
The structure of each report line: a line number, a closing parenthesis, the category label, a space, a colon, a space, and the integer value. Four output lines total, three of which depend on the input and one of which is a fixed constant.
This type of problem is common in placement assessments because it separates students who read specs carefully from those who guess at the output format. For context on where these coding tests appear in the broader placement timeline, see the guide to IT jobs for freshers.
Reading the Output Format
The output format has four rules. All four must hold on every test case.
- No space between the number and the bracket:
1)not1) - No space between the bracket and the category label:
1)Deadnot1) Dead - A space before and after the colon:
Dead : 2000notDead:2000orDead: 2000 - The final line
Please help the people who are suffering!!!is a constant, not computed from the inputs
Of these four, the colon spacing is the most commonly wrong. Many students write Dead:2000 or Dead :2000 from habit. The correct form has exactly one space on each side of the colon. One wrong character anywhere in the output is a Wrong Answer.
Online judges use exact string matching. Your output is compared byte by byte against the expected output. There is no partial credit. A correct answer with one extra space fails just as definitively as a completely wrong answer. This holds across every company’s online assessment round. Technical hiring at companies like Texas Instruments, where the analog and digital placement rounds include structured coding tasks, similarly requires output that matches a specification exactly.
The habit to build here is simple: before writing code, copy the expected output from the problem statement into a comment or a scratch pad, identify every formatting character explicitly, and verify your code reproduces each one.
Solutions in C, Java and Python
C
The C solution uses scanf to read each integer and printf to build the output lines. The format string in printf carries the label, spacing, and format specifier in one declaration.
#include <stdio.h>
int main() {
int dead, injured, safe;
scanf("%d", &dead);
scanf("%d", &injured);
scanf("%d", &safe);
printf("1)Dead : %d\n", dead);
printf("2)Injured : %d\n", injured);
printf("3)Safe : %d\n", safe);
printf("Please help the people who are suffering!!!");
return 0;
}
The %d specifier substitutes the integer value directly into the string at that position. The prefix "1)Dead : " is a string literal that encodes the entire label, including the exact spacing. The \n at the end of each report line moves the cursor to the next line. The final printf omits \n because the problem does not show a trailing newline in the expected output; most judges accept either form, but matching the spec exactly is safest.
Three separate scanf calls keep the reads simple. You can also use a single scanf("%d%d%d", &dead, &injured, &safe); both are correct since the inputs are whitespace-separated.
Java
In Java, Scanner handles input and System.out.println prints each line. String concatenation with + converts the integer to a string and appends it.
import java.util.Scanner;
public class TsunamiReport {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int dead = sc.nextInt();
int injured = sc.nextInt();
int safe = sc.nextInt();
System.out.println("1)Dead : " + dead);
System.out.println("2)Injured : " + injured);
System.out.println("3)Safe : " + safe);
System.out.println("Please help the people who are suffering!!!");
sc.close();
}
}
sc.nextInt() reads the next whitespace-delimited integer from the input stream, so it handles both newline-separated and space-separated input without changes. The expression "1)Dead : " + dead converts dead to a String automatically because the left operand of + is already a String. Calling sc.close() prevents resource-leak warnings in competitive programming environments and is good practice.
You can also use System.out.printf("1)Dead : %d%n", dead) for the same result. The printf approach aligns more closely with the C solution and is useful if you are porting code across languages.
Python
Python’s f-strings, introduced in Python 3.6 and described in the Python built-in functions reference, produce the cleanest solution. Each output line is a single print call with an inline f-string.
dead = int(input())
injured = int(input())
safe = int(input())
print(f"1)Dead : {dead}")
print(f"2)Injured : {injured}")
print(f"3)Safe : {safe}")
print("Please help the people who are suffering!!!")
int(input()) reads a line from stdin and converts it to an integer in one step. The f-string prefix f tells Python to evaluate any {expression} inside the string and substitute the result. So f"1)Dead : {dead}" with dead = 2000 produces "1)Dead : 2000" exactly. The print function appends a newline automatically after each call, so no \n is needed.
A common alternative is print("1)Dead :", dead). Avoid this. Python’s multi-argument print inserts a separator between arguments, by default a single space. The call print("1)Dead :", dead) produces 1)Dead : 2000 with a double space before the value. The f-string version gives character-level control over the output string. For the C printf format specifier reference, see cppreference.com printf.
Tracing the Sample
Input values: dead = 2000, injured = 3000, safe = 10000.
- Read phase: Read
2000from stdin, store indead. Read3000, store ininjured. Read10000, store insafe. - Output line 1: Substitute
deadinto"1)Dead : %d"(C) orf"1)Dead : {dead}"(Python) → prints1)Dead : 2000 - Output line 2: Substitute
injured→ prints2)Injured : 3000 - Output line 3: Substitute
safe→ prints3)Safe : 10000 - Output line 4: Print the fixed string → prints
Please help the people who are suffering!!!
Complete output:
1)Dead : 2000
2)Injured : 3000
3)Safe : 10000
Please help the people who are suffering!!!
This matches the expected output from the problem statement, character for character. No arithmetic, no conditionals, no loops. The entire solution is a read phase followed by a print phase.
On a placement test with a 90-minute window and 8 to 10 problems, this problem should take under two minutes once the format is clear. Time spent verifying the output format before writing the first line of code is time saved on debugging Wrong Answer submissions.
Common Mistakes and How to Avoid Them
Extra space after the bracket. Writing 1) Dead instead of 1)Dead is the single most common error. The spec has no space between ) and Dead. Verify your output against the problem’s sample output before submitting.
Wrong colon format. Three variants fail: Dead:2000 (no spaces), Dead :2000 (space before, none after), and Dead: 2000 (none before, space after). Only Dead : 2000 matches the spec. Read the colon spacing as three characters: space, colon, space.
Missing the final line. The message Please help the people who are suffering!!! must appear after the third category line in every test case. It is not conditional on any input value. Forgetting this line earns a Wrong Answer even when all three category lines are correct.
Using print("1)Dead :", dead) in Python. Python’s multi-argument print inserts a separator between arguments, by default a single space. The call print("1)Dead :", dead) produces 1)Dead : 2000 with a double space before the value. Use print(f"1)Dead : {dead}") or print("1)Dead : " + str(dead)) for exact control.
Integer overflow in C. The sample values go up to 10000, which fits comfortably in int. If the problem’s constraints allow values in the millions or billions, switch to long in Java or long long in C. In Python, integer size is unlimited, so overflow is not a concern.
Formatted I/O problems are a direct test of reading precision. Every experienced interviewer knows that a candidate who produces correct output on the first submission reads specifications carefully. This skill scales from this three-line problem all the way to writing production code against an API contract.
The f-string syntax from the Python solution, f"1)Dead : {dead}", is the same template-variable pattern used to build structured prompts for LLM APIs: you write a template string, slot in variables at runtime, and send the result to an endpoint. If that next step interests you, TinkerLLM costs ₹299 and puts actual LLM API access in your hands with Python notebooks, applying that same formatting intuition to building real AI tools.
Primary sources
Frequently asked questions
What is the exact output format for the Tsunami report program?
Each line follows the pattern `N)Category : value` with no space between the number and the bracket, no space between the bracket and the category name, and a space before and after the colon. The final line is the fixed string `Please help the people who are suffering!!!`
Why does the output use `1)Dead` with no space after the bracket?
The problem specification uses `1)Dead` without a space. Online judges match output character by character, so even one extra space causes a Wrong Answer verdict.
Can I use C++ for this problem?
Yes. Use `cin` for input and `cout` with `endl` or `\n` for output. The logic is identical to the C solution, just with C++ stream I/O replacing `scanf` and `printf`.
What data type should I use for the input integers?
The sample uses values up to 10000. Use `int` in C/C++/Java or `int()` in Python. If a test case could use very large values, `long` in Java or `long long` in C++ is a safer choice.
My output looks correct but I am still getting Wrong Answer — why?
Check for trailing spaces at the end of each line, an extra blank line, or a missing final message. Also confirm the colon spacing: `Dead : 2000` with a space on both sides, not `Dead:2000` or `Dead: 2000`.
What does the final line mean in the output?
It is a fixed string that the reporter wants printed after every report. It does not depend on the input values, so print it verbatim for every test case.
A self-paced playground for building with LLMs.
TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.
Try TinkerLLM (₹299 launch)