uva 12338
来源:互联网 发布:旅行收纳袋 知乎 编辑:程序博客网 时间:2024/05/01 13:22
Often two words that rhyme also end in the same sequence of characters. We use this property to
define the concept of an anti-rhyme. An anti-rhyme is a pair of words that have a similar beginning.
The degree of anti-rhyme of a pair of words is further defined to be the length of the longest string S
such that both strings start with S. Thus, “arboreal” and “arcturus” are an anti-rhyme pair of degree
2, while chalkboard and overboard are an anti-rhyme pair of degree 0.
You are given a list of words. Your task is, given a list of queries in the form (i, j), print the degree
(T ≤ 35). Immediately following this line are T cases.
Each case starts with the number of strings N (1 ≤ N ≤ 105
) on a line by itself. The following N
lines each contain a single non-empty string made up entirely of lower case English characters (‘a’ to
‘z’), whose length L is guaranteed to be less than or equal to 10,000. In every case it is guaranteed
that N ∗ L ≤ 106
.
The line following the last string contains a single integer Q (1 ≤ Q ≤ 106
), the number of queries.
Each of the Q lines following contain a query made up of two integers i and j separated by whitespace
the X-th case. There should be exactly Q lines after that for each case. Each of those Q lines should
5
daffodilpacm
daffodiliupc
distancevector
distancefinder
distinctsubsequence
4
1 2
1 5
3 4
4 5
2
acm
icpc
2
1 2
8
1
8
4
Case 2:
0
define the concept of an anti-rhyme. An anti-rhyme is a pair of words that have a similar beginning.
The degree of anti-rhyme of a pair of words is further defined to be the length of the longest string S
such that both strings start with S. Thus, “arboreal” and “arcturus” are an anti-rhyme pair of degree
2, while chalkboard and overboard are an anti-rhyme pair of degree 0.
You are given a list of words. Your task is, given a list of queries in the form (i, j), print the degree
of anti-rhyme for the pair of strings formed by the i-th and the j-th words from the list.
Input
(T ≤ 35). Immediately following this line are T cases.
Each case starts with the number of strings N (1 ≤ N ≤ 105
) on a line by itself. The following N
lines each contain a single non-empty string made up entirely of lower case English characters (‘a’ to
‘z’), whose length L is guaranteed to be less than or equal to 10,000. In every case it is guaranteed
that N ∗ L ≤ 106
.
The line following the last string contains a single integer Q (1 ≤ Q ≤ 106
), the number of queries.
Each of the Q lines following contain a query made up of two integers i and j separated by whitespace
(1 ≤ i, j ≤ N).
Output
the X-th case. There should be exactly Q lines after that for each case. Each of those Q lines should
contain an integer that is the answer to the corresponding query in the input.
Sample Input
5
daffodilpacm
daffodiliupc
distancevector
distancefinder
distinctsubsequence
4
1 2
1 5
3 4
4 5
2
acm
icpc
2
1 2
2 2
Sample Output
8
1
8
4
Case 2:
0
4
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;char sh[100005][10005];int main(){ int t; scanf("%d",&t); for(int i=1;i<=t;i++) { printf("Case %d:\n",i); int m,n; scanf("%d",&m); for(int j=1;j<=m;j++) scanf("%s",sh[j]); scanf("%d",&n); for(int k=1;k<=n;k++) { int a,b; scanf("%d%d",&a,&b); int l,s=0; l=strlen(sh[a])<strlen(sh[b])?strlen(sh[a]):strlen(sh[b]); //cout <<sh[a]<<"````"<<sh[b]<<endl; for(int j=0;j<l;j++) if(sh[a][j]==sh[b][j])s++; else break; printf("%d\n",s); } //cout<<"````````over``````"<<endl; }}
阅读全文
0 0
- UVA 12338
- uva 12338
- UVA 12338
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- 搜索专题总结
- shell 脚本编程之算术运算符
- 关于MFC当中使用VC(C++)8位BMP提取Y通道平均值的笔记
- 设计模式六大原则
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column dd in where clause
- uva 12338
- Linux如何查看JDK的安装路径
- opencv 分辨率与resize
- 各种排序算法解析
- Java常用类及其方法(四)Integer
- Java实践(四)---进阶笔记之二
- 商务谈判
- The Useless Toy(水题 暴力枚举)
- cookie和jsp的简介