码迷,mamicode.com
首页 > 其他好文 > 详细

XDOJ_1054_贪心

时间:2016-10-29 18:45:50      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:acm   algo   str   color   using   code   int   include   ++   

http://acm.xidian.edu.cn/problem.php?id=1154

 

找连续0的串数量就可以了。

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

string s;

int main()
{
    while(cin >> s)
    {
        int len = s.length();
        int ans = 0,flag = 0;
        for(int now = 0;now < len;now++)
        {
            if(flag)
            {
                while(now < len)
                {
                    if(s[now] == 1)
                    {
                        ans++;
                        flag = 0;
                        break;
                    }
                    else    now++;
                }
            }
            else if(s[now] == 0)    flag = 1;
        }
        if(flag)    ans++;
        printf("%d\n",ans);
    }
    return 0;
} 

 

XDOJ_1054_贪心

标签:acm   algo   str   color   using   code   int   include   ++   

原文地址:http://www.cnblogs.com/zhurb/p/6011440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!