Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1,s2,...,sn. 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 si for all i(1≤in). Help Polycarpus determine the length of the city phone code.

Input

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 s1,s2,...,sn − 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.

Output

Print the number of digits in the city phone code.

Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note

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".

简单说就是找所有号码中公共的前缀数字的数量,简单来说就是区号吧(手动滑稽)

刚开始想的时候想每个和其他的比,看看最小的公共前缀数字。

然后我就想时间复杂度O(n^2)。时间应该会超吧。所以想相邻的比吧。

还是太菜了。。只能做水题,数据结构的题一看就晕啊。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string a[];
int minlen=;
int n;
cin >> n;
for(int i=;i<n;i++)
{
cin >> a[i];
}
int len=a[].size();
for(int i=;i<n-;i++)
{
int Min=;
for(int j=;j<len;j++)
{
if(a[i][j]==a[i+][j])
Min++;
else
break;
}
//cout << Min << endl;
minlen=min(Min, minlen);
}
cout << minlen;
}

Phone Code的更多相关文章

  1. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  2. 我们是怎么做Code Review的

    前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...

  3. Code Review 程序员的寄望与哀伤

    一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...

  4. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

  5. 在Visual Studio Code中配置GO开发环境

    一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...

  6. 代码的坏味道(14)——重复代码(Duplicate Code)

    坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...

  7. http status code

    属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...

  8. Visual Studio Code——Angular2 Hello World 之 2.0

    最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ...

  9. WebStorm 2016 最新版激活(activation code方式)

    WebStorm 2016 最新版激活(activation code方式) WebStorm activation code WebStorm 最新版本激活方式: 今天下载最新版本的WebStorm ...

  10. docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用

    .net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...

随机推荐

  1. 创建SSM项目所需

    一.mybatis所需: 1.相关jar包 2.创数据库+Javabean类 3.接口+写SQL的xml映射文件 4.核心配置文件:SqlMapConfig.xml 二.springMVC所需: 1. ...

  2. Spring Cloud Alibaba学习笔记(3) - Ribbon

    1.手写一个客户端负载均衡器 在了解什么是Ribbon之前,首先通过代码的方式手写一个负载均衡器 RestTemplate restTemplate = new RestTemplate(); // ...

  3. python selenium单/复选框操作

    一.单选:radio 1.首先是定位选择框的位置 2.定位id,点击图标就可以了,代码如下(获取url地址方法:把上面源码粘贴到文本保存为.html后缀后用浏览器打开,在浏览器url地址栏复制出地址就 ...

  4. 关于sqlmapapi一点记录

    关于sqlmapapi自己练习的还是很少 今天看见freebuf上师傅的分享的内容 自己练习了一下 来自: https://www.freebuf.com/articles/web/204875.ht ...

  5. PHP array_change_key_case

    (PHP 4 >= 4.2.0, PHP 5, PHP 7) 1.函数的作用 : 改变数组所有键值的大小写: 2.参数: 1)array : 应用的数组: 2)case  : 指定转换为大写或者 ...

  6. [NOIp2014] luogu P1351 联合权值

    哎我博 4 了. 题目描述 无向连通图 GGG 有 nnn 个点,n−1n−1n−1 条边.点从 111 到 nnn 依次编号,编号为 iii 的点的权值为 WiW_iWi​,每条边的长度均为 111 ...

  7. ‎Cocos2d-x 学习笔记(11.8) DelayTime ReverseTime TargetedAction ActionFloat Blink TintTo TintBy ResizeTo ResizeBy

    1. DelayTime 通过create方法create(float d)设置时长,update方法没有任何操作.可以用于动作之间的延迟. 2. ReverseTime create方法create ...

  8. Android 使用appcompat_v7包以及源码注意事项

    最近学习和实践Android,无数次被AS和gradle惨痛的折磨,于是决定坚守Eclipse阵地..真是无奈之举,AS和gradle对我而言就像win10一样不讨喜. 当然Eclipse中开发and ...

  9. opencv::SURF特征

    SURF特征基本介绍 SURF(Speeded Up Robust Features)特征关键特性: -特征检测 -尺度空间 -选择不变性 -特征向量 工作原理 . 选择图像中POI(Points o ...

  10. Head First设计模式——装饰者模式

    前言:对于设计模式我们有时候在想是否有必要,因为实际开发中我们没有那么多闲工夫去套用这么多设计模式,也没有必要为了模式而模式. 通常这些模式会引入新的抽象层,增加代码的复杂度,但是当我们掌握了这些设计 ...