Binary Protocol

A. Binary Protocol

这道题要唯一注意的一点就是数字0的表示——0个“1”来表达,所以字符串“100”所表示的数字就是100

附代码:

// Created by CAD on 2019/8/6.
#include <bits/stdc++.h>

#define ll long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f
#define PII pair<int,int>
#define PIII pair<pair<int,int>,int>
#define mst(name, value) memset(name,value,sizeof(name))
#define FOPEN freopen("C:\\Users\\14016\\Desktop\\cad.txt","r",stdin)
#define test(n) cout<<n<<endl
using namespace std;

ll a=0;
int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    int t=0;
    for(int i=0;i<n;++i)
    {
        if(s[i]=='1') t++;
        else if(s[i]=='0') a=a*10+t,t=0;
    }
    a=a*10+t;
    cout<<a<<endl;
}



posted @ 2019-08-07 09:50  caoanda  阅读(183)  评论(0编辑  收藏  举报