#191. 统计相同首字符字符串对

    ID: 191 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatAp-1gesp3字符串循环结构

统计相同首字符字符串对

Count Same Starting Characters

Background

Congcong has been organizing his string lists recently. He has two string lists of the same length and wants to know how many pairs of strings meet a specific condition.

Problem Description

Given two arrays of strings that are the same length, compare the 1st string in one array to the 1st string in the other array, the 2nd to the 2nd, and so on. Count the number of times that the two strings are non-empty and start with the same character. The strings may be any length, including 00.

Input Format

Input is given from standard input in the following format.

The input is a single line string. This string contains two parts: the elements of the first array, followed by ] [ , then the elements of the second array. Each element is a double-quoted string, separated by spaces. For example: "s1" "s2" "s3"] ["t1" "t2" "t3"

Output Format

Output to standard output in the following format.

An integer, representing the count of string pairs that meet the condition.

Sample

"aa" "bb" "cc"] ["aaa" "xx" "bb"
1
"aa" "bb" "cc"] ["aaa" "b" "bb"
2
"aa" "bb" "cc"] ["" "" "ccc"
1

Sample Explanation

Sample 1:

  • "aa" and "aaa": Both are non-empty and start with 'a'. Count plus 11.
  • "bb" and "xx": Both are non-empty, but 'b' is not equal to 'x'.
  • "cc" and "bb": Both are non-empty, but 'c' is not equal to 'b'. Total 11 pair.

Sample 2:

  • "aa" and "aaa": Both are non-empty and start with 'a'. Count plus 11.
  • "bb" and "b": Both are non-empty and start with 'b'. Count plus 11.
  • "cc" and "bb": Both are non-empty, but 'c' is not equal to 'b'. Total 22 pairs.

Sample 3:

  • "aa" and "": "" is an empty string, condition not met.
  • "bb" and "": "" is an empty string, condition not met.
  • "cc" and "ccc": Both are non-empty and start with 'c'. Count plus 11. Total 11 pair.

Constraints

Time limit for each test case is 11 second, memory limit is 10241024 KiB.