Secret Chamber at Mount Rushmore

揭秘拉什莫尔山上隐藏的秘密厅及其内部所藏的加密历史文件,考古学家S. Dakota Jones如何解开这一谜团并尝试解读这些文件。

Secret Chamber at Mount Rushmore

                                          



By now you have probably heard that there is a spectacular stone sculpture featuring four famous U.S. presidents at Mount Rushmore. However, very few people know that this monument contains a secret chamber. This sounds like something out of a plot of a Hollywood movie, but the chamber really exists. It can be found behind the head of Abraham Lincoln and was designed to serve as a Hall of Records to store important historical U.S. documents and artifacts. Historians claim that the construction of the hall was halted in 1939 and the uncompleted chamber was left untouched until the late 1990s, but this is not the whole truth.
In 1982, the famous archaeologist S. Dakota Jones secretly visited the monument and found that the chamber actually was completed, but it was kept confidential. This seemed suspicious and after some poking around, she found a hidden vault and some documents inside. Unfortunately, these documents did not make any sense and were all gibberish. She suspected that they had been written in a code, but she could not decipher them despite all her efforts.
Earlier this week when she was in the area to follow the ACM-ICPC World Finals, Dr. Jones finally discovered the key to deciphering the documents, in Connolly Hall of SDSM&T. She found a document that contains a list of translations of letters. Some letters may have more than one translation, and others may have no translation. By repeatedly applying some of these translations to individual letters in the gibberish documents, she might be able to decipher them to yield historical U.S. documents such as the Declaration of Independence and the Constitution. She needs your help.
You are given the possible translations of letters and a list of pairs of original and deciphered words. Your task is to verify whether the words in each pair match. Two words match if they have the same length and if each letter of the first word can be turned into the corresponding letter of the second word by using the available translations zero or more times.
Input
The first line of input contains two integers m(1≤m≤500) andn(1≤n≤50), where mis the number of translations of letters andnis the number of word pairs. Each of the next mlines contains two distinct space-separated letters a and b

, indicating that the letter a can be translated to the letter b. Each ordered pair of letters (a,b)

appears at most once. Following this are n lines, each containing a word pair to check. Translations and words use only lowercase letters ‘a’–‘z’, and each word contains at least 1 and at most 50 letters.

Output

For each pair of words, display yes if the two words match, and no otherwise.

Sample Input 1

Sample Output 1

9 5c ti rk po cr ot et fu hw pwe wecan thework peopleit ofout the

yes no no yes yes

Sample Input 2

Sample Output 2

3 3a cb aa baaa abcabc aaaacm bcm

yesnoyes

题意自己去百度,说下思路,这道题就是简单的置换,字母间的置换(但是必须是前面的数可以转化成后面的数,后面的不可以转化为前面的),用二维数组存储,但是还有一些字母存在间接联系,例如q w,w v,从这两组还可以得到q v之间的转化,然后进行比较就好,代码如下:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char a[1000],b[1000];
int d[30][30];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m))
    {
        char x,y;
        memset(d,0,sizeof(d));
        for(int i=1;i<=n;i++)
        {
            getchar();//吸收回车
            scanf("%c %c",&x,&y);
            d[x-'a'][y-'a']=1;
        }
        for(int i=0;i<26;i++)
        {
            for(int j=0;j<26;j++)
            {
                if(d[i][j])
                {
                    for(int k=0;k<26;k++)
                    {
                        if(d[k][i])
                            d[k][j]=1;//有间接联系的
                    }
                }
            }
        }
        for(int p=1;p<=m;p++)
        {
            scanf("%s%s",a,b);
            int e1=strlen(a);
            int e2=strlen(b);
            int i=0,j=0,flag=0;
            while(i<e1&&j<e2&&i==j&&flag==0)
            {
                if(a[i]==b[j]||d[a[i]-'a'][b[j]-'a']==1)
                    i++,j++;
                else
                    flag=1;
            }
            if(e1==e2&&flag==0)
                printf("yes\n");
            else
               printf("no\n");
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值