URAL 1545. Hieroglyphs

1545. Hieroglyphs

Time limit: 1.0 second
Memory limit: 64 MB
Vova is fond of anime. He is so enthusiastic about this art that he learned to communicate with his Japanese friends using their native language. However, for writing email messages Vova has to use Latin letters. He wants to type hieroglyphs from his keyboard. His team-mate Sergey, in order to help Vova, created an applet that makes it possible to write hieroglyphs by means of typing Latin letters on the keyboard. Each hieroglyph is represented by a sequence of two Latin letters. This correspondence is given in a special reference book compiled by Sergey. When the applet realizes that a sequence of Latin letters corresponding to a hieroglyph has been typed, it replaces the sequence with this hieroglyph.
When Vova started using Sergey's program, he quickly became bored of looking into the reference book so often. Help Sergey to upgrade the applet in such a way that for each typed Latin letter it would automatically supply a prompt helping to continue this letter to a sequence representing a hieroglyph.

Input

The first line contains the number of hieroglyphs in Sergey's reference book  N (1 ≤  N ≤ 1000). Each of the next  N lines contains a sequence of two lowercase Latin letters corresponding to a hieroglyph. The next line contains a lowercase Latin letter entered by Vova.

Output

Output sequences from the reference book that start with the given letter, one sequence per line, in an arbitrary order. If there are no such sequences, then output nothing.

Sample

input output
6
na
no
ni
ki
ka
ku
k
ka
ki
ku




题意:输出n个字符串中以给出的字母开头的字符串。顺序不限。

解析:遍历一遍即可。



AC代码:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

string s[1002];

int main(){
    #ifdef sxk
        freopen("in.txt", "r", stdin);
    #endif //sxk

    int n;
    char c;
    while(scanf("%d", &n)==1){
        for(int i=0; i<n; i++) cin>>s[i];
        cin>>c;
        for(int i=0; i<n; i++)
            if(s[i][0] == c) cout<<s[i]<<endl;
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值