Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

很水(附代碼)

Posted by miklcct at 2011-08-02 16:29:06 on Problem 3095
#include <iostream>
#include <string>

int score(const std::string &s, int index) {
    switch (s[index]) {
        case '.':
            return 2;
        case '_':
            return 0;
        case '/':
            --index;
            while (index >= 0) {
                switch (s[index]) {
                    case '|':
                    case '\\':
                        return 0;
                    case '.':
                        return 2;
                }
                --index;
            }
            return 2;
        case '\\':
            ++index;
            while (index < s.length()) {
                switch (s[index]) {
                    case '|':
                    case '/':
                        return 0;
                    case '.':
                        return 2;
                }
                ++index;
            }
            return 2;
        case '|':
            {
                int sum = 0;
                std::string copy = s;
                copy[index] = '\\';
                sum += score(copy, index);
                copy[index] = '/';
                sum += score(copy, index);
                return sum / 2;
            }
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::string s;
    std::cin >> s;
    while (s != "#") {
        int sum = 0;
        for (int i = 0; i < s.size(); ++i) {
            sum += score(s, i);
        }
        std::cout << sum * 100 / (s.size() * 2) << '\n';
        std::cin >> s;
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator