2021-04-15 AOJ ALD1_3_D

感觉这道题真好啊,如果是之前的我,肯定是不会做这种题的,有机会能碰到这种题目看起来很难,但是其实道理很简单的题,真是一件特别幸运的事

#include
#include
#include
#include
using namespace std;
const int maxn = 20001;
int stack_left[maxn], left_cur = -1, area_cur = -1;
pair stack_area[maxn];
int main() {
    char str[maxn]; scanf("%s", str);
    int len = strlen(str);
    int sum_area = 0;
    for (int i = 0; i < len; i++) {
        if (str[i] == '\\')stack_left[++left_cur] = i;
        else if (str[i] == '/' && left_cur >= 0) {
                int sum = 0, j = 0;
                j = stack_left[left_cur--];
                sum = i - j;
                sum_area += sum;
                while (area_cur >= 0 && stack_area[area_cur].first > j) sum += stack_area[area_cur--].second;
                stack_area[++area_cur] = pair(j, sum);
        }
    }
    printf("%d\n%d", sum_area,area_cur + 1);
    for (int i = 0 ; i <= area_cur; i++) printf(" %d", stack_area[i].second);
    printf("\n");
}

你可能感兴趣的:(2021-04-15 AOJ ALD1_3_D)