首页 > ACM题库 > HDU-杭电 > hdu 2140 Michael Scofield’s letter-字符串处理-[解题报告]C++
2013
12-29

hdu 2140 Michael Scofield’s letter-字符串处理-[解题报告]C++

Michael Scofield’s letter

问题描述 :

I believe many people are the fans of prison break. How clever Michael is!! In order that the message won’t be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the heart of Sara. Now can you write a program to help Sara encode the letter from Michael easily?
The letter from Michael every time is a string of lowercase letters. You should encode letters as the rules below:
b is ‘ ‘, q is ‘,’, t is ‘!’, m is l, i is e, c is a, a is c, e is i, l is m. It is interesting. Are you found that it is just change michael to leahcim?

输入:

The input will consist of several cases, one per line.
Each case is a letter from Michael, the letteres won’t exceed 10000.

输出:

The input will consist of several cases, one per line.
Each case is a letter from Michael, the letteres won’t exceed 10000.

样例输入:

pmicsibforgevibliqbscrct
ebmovibyout

样例输出:

please forgive me, sara!
i love you!

2011-12-15 02:28:25

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2140

题意:给出加密的字符串,输出解密。加密规则在题中。

mark:那个l很像1……wa了一次,没看数组范围,开了个100的,2B了。

代码:

# include <stdio.h>


char tab[300] ;
char str[10010] ;


int main ()
{
    int i ;
    char s1[] = "bqtmicael", s2[] = " ,!leacim" ;

    for (i = 0 ; i < 9 ; i++)
        tab[s1[i]] = s2[i] ;
    while (gets (str))
    {
        for (i = 0 ; str[i] ; i++)
        {
            if (tab[str[i]] == 0) putchar (str[i]) ;
            else putchar (tab[str[i]]) ;
        }
        printf ("\n") ;
    }
}

解题转自:http://www.cnblogs.com/lzsz1212/archive/2012/01/06/2314621.html


  1. #include <stdio.h>
    int main(void)
    {
    int arr[] = {10,20,30,40,50,60};
    int *p=arr;
    printf("%d,%d,",*p++,*++p);
    printf("%d,%d,%d",*p,*p++,*++p);
    return 0;
    }

    为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下?

  2. 可以参考算法导论中的时间戳。就是结束访问时间,最后结束的顶点肯定是入度为0的顶点,因为DFS要回溯