Skip to content

S2Q2 · Ceil Marks to Nearest Tens if Close

⚡ Quick Reference

Type: Full I/O problem

Core idea: if the units digit of the marks is 8 or 9, round up to the next ten; print only updated records.

n = int(input())
for _ in range(n):
    roll, marks = input().split()
    marks = int(marks)
    if marks % 10 in (8, 9):
        updated = (marks // 10 + 1) * 10
        print(f"{roll},{updated}")

Key rules: - Units digit 8 or 9 → round up to next ten - All other marks → unchanged, not printed - Output format: roll_number,updated_marks (comma-separated, no space)


Problem Statement

Problem (I/O type)

Read n student records (roll number and marks). If marks end in 8 or 9, ceil to the next ten. Print only the records that were updated.

Example:

Input
4
R01 48
R02 69
R03 70
R04 37
Output
R01,50
R02,70

R03 (marks=70) and R04 (marks=37) are unchanged - not printed.


Tracing the example

Roll Marks Units digit Updated? New marks Print?
R01 48 8 ✅ (4+1)×10 = 50
R02 69 9 ✅ (6+1)×10 = 70
R03 70 0 ❌ -
R04 37 7 ❌ -

Solution approaches

n = int(input())
for _ in range(n):
    roll, marks = input().split()
    marks = int(marks)
    if marks % 10 in (8, 9):
        print(f"{roll},{(marks // 10 + 1) * 10}")
n = int(input())
for _ in range(n):
    line  = input().split()
    roll  = line[0]
    marks = int(line[1])

    units = marks % 10
    if units == 8 or units == 9:
        updated = (marks // 10 + 1) * 10
        print(roll + "," + str(updated))
import math

n = int(input())
for _ in range(n):
    roll, marks = input().split()
    marks = int(marks)
    if marks % 10 in (8, 9):
        updated = math.ceil(marks / 10) * 10
        print(f"{roll},{updated}")

math.ceil(marks / 10) * 10 rounds up to the next multiple of 10. Equivalent to (marks // 10 + 1) * 10 when units digit is 8 or 9.

ceil_tens = lambda m: (m // 10 + 1) * 10

n = int(input())
for _ in range(n):
    roll, marks = input().split()
    marks = int(marks)
    if marks % 10 in (8, 9):
        print(f"{roll},{ceil_tens(marks)}")

Key takeaways

01

marks % 10 in (8, 9) - clean membership test

Using in (8, 9) is cleaner than == 8 or == 9. The in operator checks membership in any iterable - a tuple is idiomatic for small sets of values.

02

(marks // 10 + 1) * 10 rounds up to next ten

Floor divide by 10 gives the current tens digit, adding 1 moves to the next, multiplying by 10 scales back up. For marks=48: (4+1)×10 = 50. For marks=69: (6+1)×10 = 70.

03

Only print updated records

The print is inside the if block - unchanged records are silently skipped. No need to store all records; process and print in one pass.