Review of Codeforces 5A and 5B(Python)
来源:互联网 发布:电子相册视频制作软件 编辑:程序博客网 时间:2024/05/05 11:34
5A. Chat Server's Outgoing Traffic
Seems like a simple task. However, you may find it is difficult to tell the determination of the input. There are two method: first one is using sys.stdin. you may need to learn how to use sys model. The second method is using exeption method(try...catch)
source code as follows:
v, m = 0, 0while True: try: temp = raw_input() except : break if temp[0] == '+': m += 1 elif temp[0] == '-': m -= 1 else: i = temp.index(':') v += len(temp[i+1::]) * mprint v
5B Center Alignment
if you have the exps of UI, this problem is easy to solve. also use try...catch to deal with the input, source code as follows:
v = []while True: try: s = raw_input() except : break l = len(s) v.append([s, l])vm = v[:]vm.sort(key = lambda x : x[1])width = vm[-1][1] + 2cc = 0print '*' * widthfor i in xrange(len(v)): temp = v[i] if (width - temp[1]) % 2: if cc % 2 == 0: temp[0] += ' ' temp[1] += 1 cc += 1 else : temp[0] = ' ' + temp[0] temp[1] += 1 cc += 1 sw = (width - temp[1]) / 2 lw = '*' + ' '*(sw-1) rw = ' '*(sw-1) + '*' temp[0] = lw + temp[0] + rw print temp[0]print '*' * width
0 0
- Review of Codeforces 5A and 5B(Python)
- Review of codeforces 493B Vasya and Wrestling based on Python
- Review of Codeforces 6B and 6C
- Review of codeforces 483B Friends and Presents
- Review of codeforces 486B
- Review of codeforces 484A Bits based on python
- codeforces 850B Arpa and a list of numbers
- Codeforces Round #432 B. Arpa and a list of numbers
- Review of codeforces 492C Vanya and Computer Game based on Python
- Review of Codeforces 5C. Longest Regular Bracket Sequence
- codeforces A and B and Interesting Substrings
- A literature review and classification of recommender systems research
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- Codeforces Round #432 (Div. 1): B. Arpa and a list of numbers
- Codeforces Round #432 (Div. 2) D 850B Arpa and a list of numbers(gcd 枚举)
- codeforces 580B Arpa and a list of numbers 前缀和+思维+分块 (调和级数)
- Codeforces Round #432 (Div. 1) B. Arpa and a list of numbers
- Python and or ?A:B
- [补充一]3D视频
- Linux进程实时IO监控iotop命令详解
- [ACM] POJ 2689 Prime Distance (大区间素数筛选)
- gitolite3的安装
- sqoop导入mysql数据到hive中报错
- Review of Codeforces 5A and 5B(Python)
- Linux IO实时监控iostat命令详解
- 内核zImage的制作(initramfs)
- 鸡尾酒疗法
- PHP父类调用子类方法
- C/C++动态二维数组的内存分配和释放 .
- C++操作符重载
- 小马哥-----高仿山寨5S 仿苹果5S拆机主板图与开机界面图 国产苹果 警惕上当
- C++引用传递和值传递