HihoCoder 1326 有序01字符串 暴力枚举

题目链接


暴力枚举结果情况,然后跟当前比较,找到最小次数

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int t;
char s[1005];
int main()
{
    scanf("%d", &t);
    while(t--)
    {
        scanf("%s", s);
        int n = strlen(s);
        int ans = 1e9;
        for(int i = 0; i <= n; i++)
        {
            int tmp = 0;
            for(int j = 0; j < i; j++)
                if(s[j] != '0') tmp++;
            for(int j = i; j < n; j++)
                if(s[j] != '1') tmp++;
            ans = min(tmp, ans);
        }
        printf("%d\n", ans);
    }
    return 0;
}
posted @ 2017-08-20 00:11  可达龙  阅读(254)  评论(0编辑  收藏  举报