WOJ1043-Magic Star
来源:互联网 发布:网络语言20米是多少钱 编辑:程序博客网 时间:2024/05/19 13:59
There is a story that people who have the similar names will get along well with each other.So when finding a girl friend, you can
take this point into consideration ^_^.
In MagicStar , people have a way to count the comparability between two names : the comparability between "kinfkong" and "kingkong"
is 3 because they have the same prefix "kin", while it is 0 between the names "kinfkong" and "dingkong" which have not common prefix.
Every person has an ID and a name. Dr.Longge want to count the sum of the comparabilities of q pairs of persons in the same set.
Can you help him?
输入格式
In the first line there is n (1<n<=6000) indicating the number of people in MagicStar. The following n lines each containing an ID
and a name for a person. The length of the names is at least one but no more than 1000.IDs are in the range of 1 and n.
No two IDs are the same. Next line is a number m. Then m sets follow.Each set starts with a number q in a line, meaning there are q queries
in this set. Every query is made up of two IDs in a line. (m*q <= 10^6) .
输出格式
You task is to output m numbers, one in a line . The ith number is total comparabilities of the ith set.
样例输入
41 kingkong2 dinfkong3 kinfkong4 kinfkonq221 23 411 2
样例输出
70
#include<stdio.h>#include<string.h>char name[6001][1001];char n1[1001],n2[1002];int n,m,q;int main(){int ans,i,j,k;scanf("%d",&n);while(n--){scanf("%d",&i);scanf("%s",&name[i]);}scanf("%d",&m);while(m--){scanf("%d",&q);ans=0;while(q--){scanf("%d %d",&i,&j);for(k=0;name[i][k]!='\0'&&name[j][k]!='\0';k++){if(name[i][k]!=name[j][k])break;}ans+=k;}printf("%d\n",ans);}return 0;}
- WOJ1043-Magic Star
- Star
- Star
- Star
- star
- star
- 【magic】
- magic
- Magic
- magic
- Star Trek
- A star
- star(CD1231)
- poj2352 Star
- A star
- 百度star
- FZOJ2110: Star
- A Star
- ORACLE日期转换成汉字某年某月某日
- linux中查找包含某关键字的文件
- ASP.NET Core
- [Android] Android assets目录下资源使用
- c++中指针和数组的区别
- WOJ1043-Magic Star
- Linux静态链接库,动态链接库,动态加载库
- python
- 51nod1344-贪心&进制思想&好题-砝码称重
- 屏幕适配(C3)
- settimeout中的函数this指向window
- 新词发现及Java和spark实现
- 【TensorFlow 官网 可以直接访问】让中国开发者更容易地使用TensorFlow打造人工智能应用
- Android ConstraintLayout属性详解