#191. 统计相同首字符字符串对
统计相同首字符字符串对
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 .
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 ."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 pair.
Sample 2:
"aa"and"aaa": Both are non-empty and start with 'a'. Count plus ."bb"and"b": Both are non-empty and start with 'b'. Count plus ."cc"and"bb": Both are non-empty, but 'c' is not equal to 'b'. Total 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 . Total pair.
Constraints
Time limit for each test case is second, memory limit is KiB.