BUAA Training 2013 #1

本文介绍了BUAA训练赛的几道编程题目,包括如何将输入输出转换为正确格式,找出权重序列,以及判断括号序列是否为有效序列。涉及编程概念如字符串处理、条件判断、栈操作等。适合提高编程思维和算法理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一次训练题目发到了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 

### BUAA 面向对象编程课程的核心内容 面向对象编程(Object-Oriented Programming, OOP)作为现代软件开发的基础范式之一,在BUAA的相关课程中得到了深入探讨。该课程不仅注重理论知识的学习,还通过实践项目强化学生对OOP的理解和应用能力。 #### 1. **课程目标** - 本课程旨在引导学生从传统的面向过程编程转向更加灵活高效的面向对象思维方式[^1]。 - 学生能够掌握核心概念如封装、继承与多态,并将其应用于实际工程项目中[^2]。 - 提升代码质量的同时降低维护成本,使开发者可以专注于解决复杂的业务需求而非纠缠于低效的实现细节[^3]。 #### 2. **主要教学模块** ##### (1) **基础概念介绍** - 封装:隐藏内部状态并提供接口访问机制;保护数据安全性和一致性[^4]。 - 继承:子类可以从父类获取属性和方法,减少重复编码量[^5]。 - 多态:允许同一操作具有多种表现形式,增强系统的灵活性和扩展性。 ##### (2) **工具和技术支持** - JUnit框架被广泛用于自动化测试环节,尽管部分同学对其强制性的覆盖率要求存在异议,但它确实有助于发现潜在缺陷并提高产品质量^。 ```java @Test public void testAddition() { Calculator calc = new Calculator(); assertEquals(4, calc.add(2, 2)); } ``` ##### (3) **实战演练——迭代作业体系** - 通过五个阶段逐步深化的知识点引入方式,帮助学员构建完整的OOP技能树。 - 初始阶段重点在于熟悉基本语法规则及简单类的设计思路;后期逐渐过渡至复杂场景下的综合运用能力培养。 #### 3. **常见反馈与改进建议** - 许多参与者反映JUnit学习曲线陡峭且缺乏足够的官方文档支撑,因此建议增设专门针对此主题的教学资源。 - 另外还有呼声较高的几点改进方向包括但不限于延长授课周期匹配现有任务负荷水平、提前阐明重要技术要点以便规避不必要的返工现象发生等等. --- ###
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值