topcoder SRM 593 DIV2 RaiseThisBarn

OpenSoucre發表於2013-10-14
#include <vector>
#include <string>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <queue>

using namespace std;

class RaiseThisBarn
{
public:
    int calc(string str){
        int num = count(str.begin(),str.end(),'c');
        if(num == 0 ) return str.length()-1;
        else if(num%2 != 0) return 0;
        else{
            int c_num =0,i;
            for(i = 0 ; i < str.length()&& c_num < num/2; ++ i){
                if(str[i] == 'c') c_num++;
            }
            int firstPart = i,lastPart = i;
            for(; i <str.length(); ++ i){
                if(str[i] == 'c') {lastPart = i;break;}
            }
            return lastPart - firstPart+1;
        }
    }

 

相關文章