0% found this document useful (0 votes)
6 views3 pages

Practice Exercise 10

This document outlines a practice exercise for CS110 focusing on file handling, searching, and sorting. It includes three questions: validating a Sudoku grid, finding the maximum number of nested envelopes, and sorting unique words from a list. Each question specifies input and output formats, and requires verification by a TA before leaving the lab.

Uploaded by

Munesh Meena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Practice Exercise 10

This document outlines a practice exercise for CS110 focusing on file handling, searching, and sorting. It includes three questions: validating a Sudoku grid, finding the maximum number of nested envelopes, and sorting unique words from a list. Each question specifies input and output formats, and requires verification by a TA before leaving the lab.

Uploaded by

Munesh Meena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practice Exercise

CS110 - Week 10
Topic: File handling, Searching, Sorting

Department of Computer Science and Engineering,


Indian Institute of Technology, Guwahati,
Semester II, Academic Year 2024 - 2025

Note: For all three questions, take inputs from the input files provided with the
questions. For Q1 and Q2, print the outputs on the console. For Q3, print the
output to an output file. The answers to the questions are hidden from you. You
may leave the lab only after a TA verifies the outputs for all three questions. No
need to upload code to the server for this practice exercise.

Question 1
Create a program to validate a completed 9x9 Sudoku grid. A valid Sudoku grid
must satisfy the following rules:

• Each row must contain all numbers from 1 to 9 without repetition.


• Each column must contain all numbers from 1 to 9 without repetition.
• Each of the nine 3x3 sub-grids (boxes) must contain all numbers from 1 to
9 without repetition.
If the Sudoku grid follows all these rules, it is considered valid; otherwise, it is
invalid.

Input format:
• The input is a 9x9 grid of integers separated by spaces. Each integer ranges
from 1 to 9.
• The grid will be read from an input text file.
Output format:

1
• Print 1 if the grid satisfies all the rules.

• Print 0 if any rule is violated.

Take input for your code from one of the input files at a time and check if the
output of your code matches the content of the respective output file.

Question 2
You are given a list of envelopes represented as a 2D array of integers, where en-
velopes[i] = [wi , hi ] denotes the width and height of the ith envelope.

An envelope [wi , hi ] can fit into another envelope [wj , hj ] if and only if both:

• wi < wj

• hi < hj

Your task is to find the maximum number of envelopes that can be nested inside
each other (like a Russian Doll).

Note: You cannot rotate an envelope.

Input format:

• Each line of the file contains two integers separated by a space, representing
the width wi and height hi of an envelope.

• The input will be read from a text file.

Output format:

• Print a single integer, the maximum number of envelopes that can be nested.

Constraint: 1 ≤ wi , hi ≤ 105

Example:
Input:
54
64
67
23

Output: 3
Explanation: The maximum nesting sequence is [2, 3] → [5, 4] → [6, 7].

2
Question 3
Write a C program that reads a list of words, written in lowercase, from an
input text file and performs the following tasks:

• Sorts the words in dictionary (lexicographical) order.

• Removes all duplicate words.

• Ignores blank lines and extra spaces while processing the input.

• Writes the sorted unique words to an output text file.

Input format:

• The input file contains a set of words, in lowercase, each on a new line.

• Words can have extra spaces or blank lines. These should be ignored.

Output format:

• The output file should contain the sorted unique words.

• Each word should appear exactly once on a new line.

• No extra blank line should appear in the output.

Example:
Input:
zebra
dog
cat
elephant

dog
ant

Output:
ant
cat
dog
elephant
zebra

You might also like