CF172A.Phone Code

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings _s_1, _s_2, ..., s__n. All these strings consist only of digits and have the same length.

Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each s__i for all i (1 ≤ i ≤ n). Help Polycarpus determine the length of the city phone code.

波利卡普斯在塔拉索夫市有 nn 个朋友。波利卡普斯知道他所有朋友的电话号码:这些号码是字符串 s1, s2, …, sns_1,\ s_2,\ \dots,\ s_n。所有这些字符串均由数字组成,且长度相同。

有一次,波利卡普斯需要确定塔拉索夫市的电话区号。他假设该城市的电话区号是其所有朋友电话号码的最长公共前缀。换言之,它是满足对每个 ii(其中 1≤i≤n1\le i\le n)均为 sis_i 的前缀(即开头部分)的最长字符串 cc。请帮助波利卡普斯确定该城市电话区号的长度。

输入格式

The first line of the input contains an integer n (2 ≤ n ≤ 3·104) — the number of Polycarpus's friends. The following n lines contain strings _s_1, _s_2, ..., s__n — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.

输入的第一行包含一个整数 nn(2≤n≤3⋅1042 \leq n \leq 3 \cdot 10^4)—— 表示 Polycarpus 的朋友人数。接下来的 nn 行包含字符串 s1,s2,…,sns_1, s_2, \dots, s_n —— 表示 Polycarpus 的朋友们的电话号码。保证所有字符串仅由数字组成,且长度均在 11 到 2020(含)之间。同时保证所有字符串互不相同。

输出格式

Print the number of digits in the city phone code.

输出城市电话区号的位数。

输入输出样例

  • 输入#1

    4
    00209
    00219
    00999
    00909

    输出#1

    2
  • 输入#2

    2
    1
    2

    输出#2

    0
  • 输入#3

    3
    77012345678999999999
    77012345678901234567
    77012345678998765432

    输出#3

    12

说明/提示

A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".

In the first sample the city phone code is string "00".

In the second sample the city phone code is an empty string.

In the third sample the city phone code is string "770123456789".

字符串 tt 的前缀是指通过从字符串 tt 末尾删除零个或多个字符所得到的字符串。例如,字符串 “00209” 有 6 个前缀:""(空前缀)、"0"、"00"、"002"、"0020"、"00209"。

在第一个样例中,城市电话区号为字符串 "00"。

在第二个样例中,城市电话区号为空字符串。

在第三个样例中,城市电话区号为字符串 "770123456789"。

输入解题思路,AI测评打分。不知道怎么写?

首页