Binary Protocol (Codeforces
来源:互联网 发布:js里面怎么让div隐藏 编辑:程序博客网 时间:2024/06/05 16:11
题目链接 http://codeforces.com/problemset/problem/825/A
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
- Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Print the decoded number.
3111
3
9110011101
2031
第一行输入一个整数n,第二行输入一个长度为n的字符串。题目要求按照一定的规则转换成十进制。加密规则为:
如果遇到‘1’,那么输出‘1’的连续个数;例如:1111,就输出4;111就输出3;
如果遇到‘0’,那么就输出‘0’的里阿奴个数减1(因为数字是以0隔开的);例如:11011,就输出22;110011,就输出202;
解题思路:
这就是考察逻辑思维的,不需要多解释。希望读者跟着代码走一遍,就一定会明白了其中的道理。其实非常简单。
代码:
#include<iostream>using namespace std;int main(){ int n; char c[95]; while(cin>>n) { int sum1=0; for(int i=0;i<=n-1;i++) cin>>c[i]; for(int i=0;i<=n-1;i++) { if(c[i]=='1') sum1++; else { cout<<sum1; sum1=0; } } cout<<sum1<<endl; //最终那一组数据需要最后单独输出,因为上面没有输最后一组数据 } return 0;}
- Binary Protocol (Codeforces
- Codeforces 825 A Binary Protocol
- Educational Codeforces Round 25 A. Binary Protocol
- Educational Codeforces Round 25 A. Binary Protocol
- Educational Codeforces Round 25 A Binary Protocol 基础题
- memcached binary protocol
- memcached binary protocol
- hessian binary web service protocol
- codeforce round A. Binary Protocol
- codeforces B. Quasi Binary
- codeforces #300 B. Quasi Binary
- CodeForces 538B Quasi Binary
- Codeforces - 538B - Quasi Binary
- Codeforces 92B-Binary Number
- Codeforces 830A, Binary Search
- codeforces 838A Binary Blocks
- Hessian Binary Web Service Protocol远程接口调用入门
- Protocol
- Android webview 踩坑经验总结
- hdu1025 LIS
- Enum使用
- hbase性能调优
- ios-多线程访问共享资源
- Binary Protocol (Codeforces
- java之static语法详解
- UVA
- WPF布局篇(三)
- 企业数据分析,搞定这3个重点事半功倍!
- Android尺寸转换
- 【Python】 两行命令将.py 的Python脚本 转换成.exe 程序
- Python中的map()和reduce()函数
- Python之添加新元素