Examples of EDITx coding questions

 

Question 1

 

A DNA sequence is the succession of nucleotides composing it. Each nucleotide is represented by a letter representing the base characterising it. For the DNA, there are four different bases (G, A, C or T).

A double-stranded DNA molecule is composed of two complementary sequences, given than nucleotides always pair in the same way (A with T and C with G). For example, the two following DNA sequences can form a double-stranded DNA molecule:

GATTCGA
CTAAGCT

A palindromic sequence is a DNA sequence such that reading one strand in one direction gives the same sequence as reading the complementary strand in the opposite direction. For example, the following DNA sequence is a palindromic sequence:

GAATTC
CTTAAG

****

Write a program that reads the DNA sequences from the standard input (one strand on each line) and outputs "yes" or "no" depending on whether the sequence is palindromic or not.

For example, given the following input:

GATTCGA
GAATTC
GGATCC

your program must produce the following result:

no
yes
yes

 

Test case #1

TCGA

yes

Test case #2

A

no

Test case #3

GATTCGA
GAATTC
GGATCC

no
yes
yes

 

Question 2

 

Given that the standard input contains a single lowercase word, write a program that changes the first letter of the word to a capital letter and prints the result on the standard output.

For example, given the following input:

hello

your program must produce the following result:

Hello

 

Test case #1

hello

Hello

Test case #2

a

A

 

Question 3

 

Given that the standard input contains one positive integer number, write a program that computes the factorial of this number and prints the result on the standard output.

For example, given the following input:

5

your program must produce the following result:

120

 

Test case #1

1

1

Test case #2

2

2

Test case #3

5

120

 

Question 4

 

Given that the standard input contains a list of lowercase words separated by new line characters (that is, one word per line), write a program that reads the standard input and write a list of “yes” or “no” separated by new line characters on the standard output, depending on whether the corresponding word is a palindrome or not.

For example, given the following input:

radar
island
eye
palindrome
buzz

your program must produce the following result:

yes
no
yes
no
no

 

Test case #1

radar

yes

Test case #2

sky

no

Test case #3

radar
island
eye
palindrome
buzz

yes
no
yes
no
no

 

Question 5

 

One task that many word processors can do is to clean a text, detecting and removing unintended characters. One possible cleaning is the removal of multiple spaces between words.

****

Write a program that reads the text from the standard input and outputs the same text without any multiple spaces. You can consider that multiple spaces may only be present between words and not next to punctuation signs.

For example, given the following input:

Hello   my     friend!  Long    time  no  see!     How         are   you doing?

your program must produce the following result:

Hello my friend! Long time no see! How are you doing?

 

Test case #1

A   B

A B

Test case #2

A  B   C    D

A B C D

Test case #3

Hello my friend! Long time no see! How are you doing?

Hello my friend! Long time no see! How are you doing?

 

Question 6

 

A valid email address is composed of a prefix and an email domain, separated by a @ symbol.

The prefix consists of letters (a-z), digits, underscores, periods, and dashes. The three last characters are only allowed if they are followed by one or more letters or digits. The email domain consists of blocks with letters (a-z), digits and dashes, separated by periods. The last portion must have at least two characters.

****

Given that the standard input contains a list of email address candidates separated by new line characters (that is, one candidate per line), write a program that reads the standard input and write a list of “valid” or “invalid” separated by new line characters on the standard output, depending on whether the corresponding email address candidate is valid or not.

For example, given the following input:

abc@email.com
abc-@email.com
a-b.c@mail.com
abc@mail..com
abc@a.b.c.com

your program must produce the following result:

valid
invalid
valid
invalid
valid

 

Test case #1

valid
invalid

Test case #2

Test case #3

 

Question 7

 

Every day, authorities are publishing the values of several indicators related to the health situation given the Covid-19 pandemic. Among these indicators, one is the number of new cases identified every day. Just looking at the sequence of these values does not give a useful growth or decrease tendency to make decisions. In some countries, the figure that is published every day is the average number of new cases over the 7 past days.

****

Given that the standard input contains the sequence of daily number of new Covid-19 cases identified (one positive number per line), write a program that reads the standard input and write the sequence of average value of the number of cases for the 7 past days separated by new line characters on the standard output (starting from day 7 and rounded to the smallest larger integer).

For example, given the following input:

1500
1524
1512
1412
1465
1574
1521
1514
1534

your program must produce the following result:

1502
1504
1505

 

Test case #1

1500
1524
1512
1412
1465
1574
1521
1514
1534

1502
1504
1505

 

Question 8

 

A teacher is storing the grades of its students in a text file, organised by courses. For each course, represented by a name, the teacher stores the list of students represented by their number (5 digits) with the corresponding grade.

****

Write a program that reads the text from the standard input to collect the grades of the students for each course (sections are identified by the name of the course prefixed with the # character) and outputs on the standard output the same content but organised by students. Students must be sorted in ascending order and courses must be sorted in the same order than in the original file.

For example, given the following input:

#Course_B
14365 16
12451 17.5
12476 20
#Course_A
12451 16
14365 18

your program must produce the following result:

#12451
Course_B 17.5
Course_A 16
#12476
Course_B 20
#14365
Course_B 16
Course_A 18

 

Test case #1

#Course_A
14365 16

#14365
Course_A 16

Test case #2

#Course_B
14365 16
12451 17.5
12476 20
#Course_A
12451 16
14365 18

#12451
Course_B 17.5
Course_A 16
#12476
Course_B 20
#14365
Course_B 16
Course_A 18

 

Question 9

 

Given that the standard input contains a list of integer numbers separated by a single space, on each line separated by a new line character, write a program that computes the largest value for each list of numbers, on each line of the standard output.

For example, given the following input:

0
1 2
4 -6 5 9 7

your program must produce the following result:

0
2
9

 

Test case #1

0

0

Test case #2

4 6 8 1 2

8

Test case #3

-8 -5 -1

-1

Test case #4

0
1 2
4 -6 5 9 7

0
2
9

 

Question 10

 

Given that the standard input contains a time composed of the numbers of hours, minutes, and seconds, separated by colons, write a program that computes the corresponding number of seconds and output it on the standard output.

For example, given the following input:

04:10:54

your program must produce the following result:

15054

 

Test case #1

00:00:14

14

Test case #2

00:24:43

1483

Test case #3

04:10:54

15054