Phone Code
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≤i≤n). Help Polycarpus determine the length of the city phone code.
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.
Print the number of digits in the city phone code.
4
00209
00219
00999
00909
2
2
1
2
0
3
77012345678999999999
77012345678901234567
77012345678998765432
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".
简单说就是找所有号码中公共的前缀数字的数量,简单来说就是区号吧(手动滑稽)
刚开始想的时候想每个和其他的比,看看最小的公共前缀数字。
然后我就想时间复杂度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的更多相关文章
- Visual Studio Code 代理设置
		Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ... 
- 我们是怎么做Code Review的
		前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ... 
- Code Review 程序员的寄望与哀伤
		一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ... 
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
		刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ... 
- 在Visual Studio Code中配置GO开发环境
		一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ... 
- 代码的坏味道(14)——重复代码(Duplicate Code)
		坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ... 
- http status code
		属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ... 
- Visual Studio Code——Angular2 Hello World 之 2.0
		最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ... 
- WebStorm 2016 最新版激活(activation code方式)
		WebStorm 2016 最新版激活(activation code方式) WebStorm activation code WebStorm 最新版本激活方式: 今天下载最新版本的WebStorm ... 
- docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用
		.net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ... 
随机推荐
- CH3803扑克牌
			Description 背景 lqhsr生日那天,Rainbow来找lqhsr玩扑克牌-- 玩着玩着Rainbow觉得太没意思了,于是决定给lqhsr一个考验~~~ 描述 Rainbow把一副扑克牌( ... 
- 异常:微信小程序tabBar不生效
			app.json全局tabBar设置tabBar不显示 由于小程序的机制问题,首页的tabBar第一个导航必须是首页 "pages": [ "pages/index/in ... 
- postman环境变量设置
			1.点击小齿轮进入到环境变量添加页面,点击add添加环境变量 2.输入变量名称和变量值 3.添加成功 4.接口中设置变量 
- [POI2015]PIE
			题目描述 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色.你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上的图案.印的过程中需要满足以下要求:( ... 
- opencv::处理边缘
			卷积边界问题 图像卷积的时候边界像素,不能被卷积操作,原因在于边界像素没有完全跟kernel重叠,所以当3x3滤波时候有1个像素的边缘没有被处理,5x5滤波的时候有2个像素的边缘没有被处理. 处理边缘 ... 
- HDU 5616 Jam's balance(01背包)
			题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ... 
- 【RabbitMQ 实战指南】一 RabbitMQ入门
			1.消息中间件 1.1.什么是消息中间件 消息中间件(Message Queue Middleware,简称 MQ)是指利用高效可靠的消息传递机制进行与平台无关的数据交流,并基于数据通道来进行分布式系 ... 
- java代码实现MD5加密及验证方法
			MD5加密 在我们的程序中,不管是什么,都会有安全问题,今天就说的是MD5加密的方法 MD5是哈希算法,也就是 从明文A到密文B很容易,但是从密文B到明文A几乎不可能 也就是说,给你密文,是几乎无法通 ... 
- Veins(车载通信仿真框架)入门教程
			Veins入门教程——教你如何下手研究 目录 Veins入门教程——教你如何下手研究 目录 废话少说! 讲解omnetpp.ini!(挑关键的) 讲解RSUExampleScnario.ned! 注意 ... 
- MySql悲观锁与乐观锁区别及使用场景
			一.概念上的区别 乐观锁( Optimistic Locking):顾名思义,对加锁持有一种乐观的态度,即先进行业务操作,不到最后一步不进行加锁,"乐观"的认为加锁一定会成功的,在 ... 
