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

洛谷 P2708 硬币翻转 题解

时间:2018-05-04 23:28:34      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:bit   clu   ==   print   ++   namespace   problem   tps   return   

题目传送门

真如题面所说,难度系数:☆☆☆☆☆(如果你看懂了)。

从后往前扫一次,如果a[i]==0&&a[i-1]==1那么将ans+2。

注意最后不要忘记开头if(a[0]==‘0‘) ans++;

#include<bits/stdc++.h>
using namespace std;
char a[300];int ans;
int main(){
    cin>>a;
    for(int i=strlen(a);i;i--)
        if(a[i]==0&&a[i-1]==1) ans+=2;
    if(a[0]==0) ans++;
    printf("%d\n",ans);
    return 0;
}

 

洛谷 P2708 硬币翻转 题解

标签:bit   clu   ==   print   ++   namespace   problem   tps   return   

原文地址:https://www.cnblogs.com/yzx1798106406/p/8992800.html

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