- Write a program that reads a text file and prints on the console its odd lines.
- Write a program that concatenates two text files into another text file.
- Write a program that reads a text file and inserts line numbers in front of each of its lines.
- The result should be written to another text file.
- Write a program that compares two text files line by line and prints the number of lines that are the same and the number of lines that are different.
- Assume the files have equal number of lines.
- Write a program that reads a text file containing a square matrix of numbers.
- Find an area of size
2 x 2in the matrix, with a maximal sum of its elements.- The first line in the input file contains the size of matrix
N. - Each of the next
Nlines containNnumbers separated by space. - The output should be a single number in a separate text file.
- The first line in the input file contains the size of matrix
Example:
| input | output |
|---|---|
| 4 2 3 3 4 0 2 3 4 3 7 1 2 4 3 3 2 |
17 |
- Write a program that reads a text file containing a list of strings, sorts them and saves them to another text file.
Example:
| input.txt | output.txt |
|---|---|
| Ivan Peter Maria George |
George Ivan Maria Peter |
- Write a program that replaces all occurrences of the sub-string
startwith the sub-stringfinishin a text file. - Ensure it will work with large files (e.g.
100 MB).
- Modify the solution of the previous problem to replace only whole words (not strings).
- Write a program that deletes from given text file all odd lines.
- The result should be in the same file.
- Write a program that extracts from given XML file all the text without the tags.
Example:
<?xml version="1.0"><student><name>Pesho</name><age>21</age><interests count="3"><interest>Games</interest><interest>C#</interest><interest>Java</interest></interests></student>
- Write a program that deletes from a text file all words that start with the prefix
test. - Words contain only the symbols
0…9,a…z,A…Z,_.
- Write a program that removes from a text file all words listed in given another text file.
- Handle all possible exceptions in your methods.
- Write a program that reads a list of words from the file
words.txtand finds how many times each of the words is contained in another filetest.txt. - The result should be written in the file
result.txtand the words should be sorted by the number of their occurrences in descending order. - Handle all possible exceptions in your methods.