WDTPD - Strings

12 questions

Q1
What is the output?
S = "PROGRAM"
T = ""
FOR i = 0 TO len(S)-1
    IF i MOD 2 == 0 THEN
        T = T + S[i]
    END IF
NEXT i
OUTPUT T
Q2
What is the output?
S = "ABCDEF"
T = ""
FOR i = 0 TO 2
    T = T + S[i] + S[5-i]
NEXT i
OUTPUT T
Q3
What is the output?
S = "TESTING"
T = ""
FOR i = 0 TO len(S)-1
    IF S[i] != "T" THEN
        T = T + S[i]
    END IF
NEXT i
OUTPUT T
Q4
What is the output?
S = "RACECAR"
result = 1
FOR i = 0 TO int(len(S)/2) - 1
    IF S[i] != S[len(S)-1-i] THEN
        result = 0
    END IF
NEXT i
OUTPUT result
Q5
What is the output?
S = "BANANA"
count = 0
FOR i = 0 TO len(S)-1
    IF S[i] == "A" THEN
        count = count + 1
    END IF
NEXT i
OUTPUT count
Q6
What is the output?
S = "HELLO WORLD"
words = 1
FOR i = 0 TO len(S)-1
    IF S[i] == " " THEN
        words = words + 1
    END IF
NEXT i
OUTPUT words
Q7
What is the output?
S = "COMPETITION"
T = ""
FOR i = 0 TO len(S)-1
    IF S[i] == "T" OR S[i] == "I" THEN
        T = T + S[i]
    END IF
NEXT i
OUTPUT T
Q8
What is the output?
S = "COMPUTER"
OUTPUT S[3] + S[0] + S[5]
Q9
What is the output?
S = "MISSISSIPPI"
count = 0
FOR i = 0 TO len(S)-1
    IF S[i] == "S" THEN
        count = count + 1
    END IF
NEXT i
OUTPUT count
Q10
What is the output?
S = "HELLO"
T = ""
FOR i = len(S)-1 TO 0 STEP -1
    T = T + S[i]
NEXT i
OUTPUT T
Q11
What is the output?
S = "ABCDE"
T = ""
FOR i = 0 TO len(S)-1
    T = S[i] + T
NEXT i
OUTPUT T
Q12
What is the output?
S = "ABCDEFGH"
OUTPUT S[2:5]