读书人

SRM404div2例题

发布时间: 2012-09-07 10:38:15 作者: rapoo

SRM404div2题解

250:题意是每个人读书分为3个步骤,三个步骤的顺序可以不同,当且仅当三个步骤连续出现时才算读完了一本书,给你一些字符串,问这个人最多读了几本书。贪心即可。

#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <string>using namespace std;class ReadingBooks{    public:        int countBooks(vector <string> readParts) {            int a[100], cnt = 0;            int len = readParts.size();            memset(a, 0, sizeof(a));            for (int i = 0; i < len; i++) {                if (readParts[i] == "introduction")                    a[i] = 1;                else if (readParts[i] == "story")                    a[i] = 2;                else a[i] = 4;            }            for (int i = 2; i < len; i++) {                if ((a[i] | a[i-1] | a[i-2]) == 7) {                    i += 2;                    cnt++;                }            }            return cnt;        }};

?

?

?

?

读书人网 >其他相关

热点推荐