EasyStringsNot started

Palindrome inventory codes

A warehouse flags memorable inventory codes. Read a list of lowercase codes and print how many are palindromes: codes that are identical when their characters are reversed. A one-character code counts.

Input

First line N. Next N lines each contain one lowercase code.

Output

One integer: the number of palindrome codes.

Example 1

Input

5
level
crate
r
noon
parts

Output

3

level, r and noon are palindromes.

Constraints

  • 1 <= N <= 100
  • Each code has 1 to 50 lowercase letters

Hints

Hint 1 of 3

Compare each code with a reversed copy.

Hint 2 of 3

Increase a counter only when the two strings match.

Hint 3 of 3

Python slicing [::-1] and JavaScript split/reverse/join can reverse a string.

Solution

Show a reference solution and explanation
 Python · reference solution
count = int(input())
palindromes = 0
for _ in range(count):
    code = input().strip()
    if code == code[::-1]:
        palindromes += 1
print(palindromes)

Approach

Every code is tested independently against its reverse. The counter changes only for a match, so it directly represents the number of qualifying inventory codes after the input is exhausted.

Your program
count = int(input())
palindromes = 0
for _ in range(count):
    code = input().strip()
    # test the code
print(palindromes)

Tests: 3 cases including the examples. Available in Python, JavaScript.

How this page was checked. Every reference solution, in every language listed, was run against every test case by the publishing checks. Languages marked “no run” have no in-browser runtime here yet; download your file and run it locally.