国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

x-24

2019-11-06 06:30:06
字體:
來源:轉載
供稿:網友
題目描述:DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the PRefix of another. Let's say the phone catalogue listed these numbers:- Emergency 911- Alice 97 625 999- Bob 91 12 54 26In this case, it's not possible to call Bob, because the central would direct your call to the emergency line as soon as you had dialled the first three digits of Bob's phone number. So this list would not be consistent.InputThe first line of input gives a single integer, 1 <= t <= 40, the number of test cases. Each test case starts with n, the number of phone numbers, on a separate line, 1 <= n <= 10000.Then follows n lines with one unique phone number on each line. A phone number is a sequence of at most ten digits.OutputFor each test case, output "YES" if the list is consistent, or "NO" otherwise.Sample Input2391197625999911254265113123401234401234598346Sample OutputNOYES簡單概述:即給你幾個字符串,讓你尋找是否有包含的關系,即某一字符串是不是為另一字符串的子串。解題思路:先將給出的字符串進行排序,然后尋找是否有包含的,注意運用標志flag和采用find函數。細節處理:由于習慣性問題,將尋找過程中的j寫成了i,導致不能AC,并且出現segmentation fault的錯誤。

代碼:

#include<bits/stdc++.h>using namespace std;int main(){	vector<string>v;	string s;	int m,n,i,j,k;	cin>>n;	for(i=0;i<n;i++)	{		int flag=0;		v.clear();		cin>>m;		for(j=0;j<m;j++)		{			cin>>s;			v.push_back(s);//壓入向量中		}		sort(v.begin(),v.end());		for(j=0;j<m-1;j++)		{			if(v[j+1].find(v[j])==0)//尋找是否包含子串			{				flag++;//建立的標志				}			}			 if(flag==0)			 cout<<"YES"<<endl;			 else       cout<<"NO"<<endl;		}			return 0;	}心得體會:

做題應先想清楚在敲代碼,注意一定要仔細!避免低級性錯誤!


上一篇:HDU2519

下一篇:spring整合struts2

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平罗县| 晋州市| 二手房| 健康| 准格尔旗| 民乐县| 宁国市| 丰原市| 合肥市| 辉县市| 南陵县| 梅河口市| 福州市| 清河县| 台中县| 策勒县| 武隆县| 荆门市| 东乡族自治县| 东辽县| 旬邑县| 平山县| 理塘县| 湘乡市| 清涧县| 皋兰县| 昆山市| 鸡西市| 宁化县| 新泰市| 龙口市| 洛阳市| 邳州市| 鸡泽县| 梓潼县| 深水埗区| 古交市| 井陉县| 新源县| 香河县| 日喀则市|