BUAA Training 2013 #1

第一次训练题目发到了hust上,编译各种不熟悉。。。果然在hdu做习惯了么。。。第一题上来就各种编译不通过交了10次总算过了。。。

发通知的时候也说都是很简单的题目。。。作为一个即将大三的老人,和一群大一的神犇一起训练,压力总是有的。。。但是起点不一样,自己努力就好啦~~~

不多说,上题(之前发过一次,但因为那时候训练还没有结束,就删掉了,然后,然后现在想从回收站回复的时候就无法回复了。。只能各种复制粘贴了。。。所以可能有各种问题。。。)

A - Coins
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.

Input

The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.

Output

It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.

Sample Input

Input
A>B
C<B
A>C
Output
CBA
Input
A<B
B>C
C>A
Output
ACB

水题,开始还想写拓扑排序来着。。。后来一个就三个量。。。模拟就好

  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<cstring>  
  4. #include<cstdlib>  
  5. using namespace std;  
  6. int main()  
  7. {  
  8.     int map[5]={0,0,0,0,0};  
  9.     int min=0;  
  10.     int mid=0;  
  11.     int max=0;  
  12.     char temp[10];  
  13.     while(cin>>temp)  
  14.     {  
  15.         if(temp[1]=='>')  
  16.         {  
  17.             map[temp[0]-'A']++;  
  18.         }  
  19.         if(temp[1]=='<')  
  20.         {  
  21.             map[temp[2]-'A']++;  
  22.         }  
  23.     }  
  24. //  cout<<map[2]<<endl;  
  25.     if(map[0]==map[1]||map[1]==map[2]||map[2]==map[0])  
  26.     {  
  27.         cout<<"Impossible"<<endl;  
  28.     }  
  29.     else  
  30.     {  
  31.         for(int i=0;i<3;i++)  
  32.         {  
  33.             if(map[i]==2)  
  34.             {  
  35.                 max=i;  
  36.             }  
  37.             if(map[i]==1)  
  38.             {  
  39.                 mid=i;  
  40.             }  
  41.             if(map[i]==0)  
  42.             {  
  43.                 min=i;  
  44.             }  
  45.         }  
  46.         printf("%c%c%c\n",min+'A',mid+'A',max+'A');  
  47.     }  
  48.     system("pause");  
  49.     return 0;  
  50. }  

B - Email address
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com).

It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots.

You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result.

Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at.

Input

The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols.

Output

Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages).

In the ASCII table the symbols go in this order: . @ ab...z

Sample Input

Input
vasyaatgmaildotcom
Output
vasya@gmail.com
Input
dotdotdotatdotdotat
Output
dot..@..at
Input
aatt
Output
a@t

字符串处理,也是水题。。。开始被唬住了觉得这题好难啊。。。写起来就是模拟一遍就好

  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<cstring>  
  4. #include<cstdlib>  
  5. using namespace std;  
  6. int main()  
  7. {  
  8.     char s[105];  
  9.     char ans[105];  
  10.     memset(ans,'\0',sizeof(ans));  
  11.     cin>>s;  
  12.     int n=strlen(s);  
  13.     int flag=1;  
  14.     int j=0;  
  15.     for(int i=0;i<n;i++)  
  16.     {  
  17.         if(s[i]=='d'&&s[i+1]=='o'&&s[i+2]=='t')  
  18.         {  
  19.             if(i==0)  
  20.             {  
  21.                 ans[j++]='d';  
  22.                 ans[j++]='o';  
  23.                 ans[j++]='t';  
  24.                 j=3;  
  25.                 i=2;  
  26.                 continue;  
  27.             }     
  28.             if(i+3==n)  
  29.             {  
  30.                 ans[j++]='d';  
  31.                 ans[j++]='o';  
  32.                 ans[j++]='t';  
  33.                 break;  
  34.             }  
  35.             ans[j++]='.';  
  36.             i=i+2;  
  37.             continue;  
  38.         }  
  39.         if(s[i]=='a'&&s[i+1]=='t'&&flag)  
  40.         {  
  41.             if(i==0)  
  42.             {  
  43.                 ans[0]='a';  
  44.                 ans[1]='t';  
  45.                 j=2;  
  46.                 i=1;  
  47.                 continue;  
  48.             }     
  49.             if(i+2==n)  
  50.             {  
  51.                 ans[j++]='a';  
  52.                 ans[j++]='t';  
  53.                 break;  
  54.             }  
  55.             ans[j++]='@';  
  56.             flag=0;  
  57.             i=i+1;  
  58.             continue;  
  59.         }  
  60.         ans[j++]=s[i];  
  61. //      cout<<s[i]<<endl;  
  62.     }  
  63.     for(int i=0;i<j;i++)  
  64.     {  
  65.         cout<<ans[i];  
  66.     }  
  67.     cout<<endl;  
  68. //  system("pause");  
  69.     return 0;  
  70. }  

C - Longest Regular Bracket Sequence
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

This is yet another problem dealing with regular bracket sequences.

We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.

You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.

Input

The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.

Output

Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".

Sample Input

Input
)((())))(()())
Output
6 2
Input
))(
Output
0 1

栈的应用,不同的是这题不能单纯的遇到’(‘进栈遇到’)‘出栈,而应该每当遇到'('时记录前面完整括号的个数并且将该pair入栈,具体看代码就好(pair真心方便,写了好几次逐渐会用了)

  1. #include<iostream>  
  2. #include<stack>  
  3. #include<cstring>  
  4. #include<cstdlib>  
  5. #include<cstdio>  
  6. using namespace std;  
  7. int main()  
  8. {  
  9.     char str[1000005];  
  10.     cin>>str;  
  11.     int n=strlen(str);  
  12.     stack<pair<char,int> >s;  
  13.     int ans=0;  
  14.     int cnt=1;  
  15.     int num=0;  
  16.     for(int i=0;i<n;i++)  
  17.     {  
  18.         if(str[i]=='(')  
  19.         {  
  20.             s.push(make_pair(str[i],num));  
  21.             num=0;  
  22.         }  
  23.         if(str[i]==')')  
  24.         {  
  25.             if(s.empty())  
  26.             {  
  27.                 num=0;  
  28.             }  
  29.             else  
  30.             {  
  31.                 int temp=s.top().second;  
  32.                 s.pop();  
  33.                 num=num+temp+2;  
  34.                 if(num>ans)  
  35.                 {  
  36.                     ans=num;  
  37.                     cnt=1;  
  38.                 }  
  39.                 else if(num==ans && ans!=0)  
  40.                 {  
  41.                     cnt++;  
  42.                 }  
  43.             }  
  44.         }  
  45.     }  
  46.     cout<<ans<<" "<<cnt<<endl;  
  47. //  system("pause");  
  48.     return 0;  
  49. }  

D - Very Interesting Game
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representing a number that does not exceed b. Here a and b are some given constants, s1 and s2 are chosen by the players. The strings are allowed to contain leading zeroes.

If a number obtained by the concatenation (joining together) of strings s1 and s2 is divisible by mod, then the second player wins. Otherwise the first player wins. You are given numbers abmod. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.

Input

The first line contains three integers abmod (0 ≤ a, b ≤ 1091 ≤ mod ≤ 107).

Output

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值