Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

A. Neverending competitions

time limit per test:2 seconds

memory limit per test:512 megabytes

input:standard input

output:standard output

There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name “snookah”)! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.

Jinotega’s best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
• this list contains all Jinotega’s flights in this year (in arbitrary order),
• Jinotega has only flown from his hometown to a snooker contest and back,
• after each competition Jinotega flies back home (though they may attend a competition in one place several times),
• and finally, at the beginning of the year Jinotega was at home.

Please help them to determine Jinotega’s location!

Input

In the first line of input there is a single integer n: the number of Jinotega’s flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega’s home airport. In the next n lines there is flight information, one flight per line, in form “XXX->YYY”, where “XXX” is the name of departure airport “YYY” is the name of arrival airport. Exactly one of these airports is Jinotega’s home airport.

It is guaranteed that flights information is consistent with the knowledge of Jinotega’s friends, which is described in the main part of the statement.

Output

If Jinotega is now at home, print “home” (without quotes), otherwise print “contest”.

Examples

Input
4
SVO
SVO->CDG
LHR->SVO
SVO->LHR
CDG->SVO

Output
home

Input
3
SVO
SVO->HKT
HKT->SVO
SVO->RAP

Output
contest

Note

In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
题意:给出一系列的行程,问最后在哪?
题解:题意题,从家出发-1,回家+1.判断是否为0即可。
代码:

#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int n;
string s,ss,a;
int ans[10000];
int main()
{
    scanf("%d",&n);
    memset(ans,0,sizeof(ans));
    int tot=1;
    cin>>a;
    mp[a]=tot++;
    for(int i=1; i<=n; i++)
    {
        cin>>a;
        s=a.substr(0,3);
        ss=a.substr(5,6);
        if(mp.find(s)==mp.end())
            mp[s]=tot++;
        if(mp.find(ss)==mp.end())
            mp[ss]=tot++;
        ans[mp[s]]--;
        ans[mp[ss]]++;
    }
    if(ans[1]==0)
        cout<<"home"<<endl;
    else cout<<"contest"<<endl;
}

B. Code obfuscation

time limit per test:2 seconds

memory limit per test:512 megabytes

input:standard input

output:standard output

Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That’s why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.

To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn’t use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.

You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya’s obfuscation.

Input

In the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.

Output

If this program can be a result of Kostya’s obfuscation, print “YES” (without quotes), otherwise print “NO”.

Examples

Input
abacaba

Output
YES

Input
jinotega

Output
NO
题意:用a代替第一个出现的变量,用b代替第二个出现的变量。。。
问给出的串是否满足。
题解:模拟即可。注意第一个字母必须是a。
代码:

#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int n;
string s,ss,a;
int ans[10000];
int main()
{
    char tmp='a';
    cin>>s;
    if(s[0]!='a') return 0*printf("NO\n");
    else
    {
        for(int i=0;i<s.length();i++)
        {
            if(s[i]==tmp)
            {
                tmp++;
                mp[s[i]]=1;
            }
            else if(mp[s[i]]) continue;
            else
            {
                return 0*printf("NO\n");
            }
        }
    }
    return 0*printf("YES\n");
}
阅读更多
版权声明:加油 加油 加油^-^ https://blog.csdn.net/qq_33183401/article/details/55522413
文章标签: codeforces
个人分类: Codeforces
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭