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
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

代码

Posted by cavatina2016 at 2020-08-01 01:17:44 on Problem 3991
In Reply To:算法与证明 Posted by:cavatina2016 at 2020-08-01 01:14:00
#include <stdio.h>
#include <cstring>
#include <stdlib.h>
#define MAX_N	2000


int n;
char str[2001];
char stack[2001];
int stackcount;


int calc2()
{
	int res = 0;
	stackcount = 0;

	for (int i = 0; i < n; ++i) {
		if (str[i] == '{') {
			stack[stackcount++] = '{';
		}
		else if (stackcount > 0) {
			stackcount--;
		}
		else {
			stack[stackcount++] = '{';
			res++;
		}
	}

	if (stackcount > 0) {
		while (stackcount % 2) printf("...");
		res += stackcount / 2;
	}

	return res;
}



int main()
{
	for (int t = 1; ; ++t) {
		scanf_s("%s", str, 10000);
		if (str[0] == '-') break;
		n = strlen(str);
		while (n < 1 || n > MAX_N || n % 2) printf("...");
		printf("%d. %d\n", t, calc2());
	}
    return 0;
}

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