Source Code Status Test Cases
    Policy: public     Reviewed: 7    
01.67 sec    3140 KB    66 lines     1032 bytes    2017-05-20 04:31
#include <iostream>
#include <string>
#include <cstdlib>

int cket(std::string &str, int i)
{
	int n = 1;

	for ( ; i < str.size(); ++i ) {
		if ( str[i] == '(' ) n++;
		if ( str[i] == ')' ) n--;

		if ( n == 0 ) break;
	}
	return i;
}

int n;
char expand(std::string str)
{
	std::string res;
	for ( int i = 0; i < str.size(); ++i ) {
		if ( isdigit( str[i] ) ) {
			int j = 1;
			while ( isdigit(str[i + j] ) ) j++;
			int num = std::atoi(str.substr(i, j).c_str());
			
			int s, e;
			if ( str[i + j] == '(' ) {
				int k;
				k = cket(str, i + j + 1);
				s = i + j + 1;
				e = k - (i+j+1);
				i = k;
			} else {
				s = i + j;
				e = 1;
				i = i + j;
			}
			for ( int l = 0; l < num; ++l ){
				char a = expand(str.substr(s, e));
				if ( a != '0' ) return a;
			}
		} else {
			if ( n == 0 ) {
				return str[i];
			}
			n--;
		}
	}
	return '0';
}

int main(void)
{
	while ( true ) {
		std::string str;

		std::cin >> str >> n;
		if ( str == "0" && n == 0 ) break;

		std::cout << expand(str) << std::endl;
	}
	return 0;
}

Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 C++ CPU: 01.67 sec Memory: 3140 KB Length: 1032 B 2017-05-20 04:31 2017-05-20 04:31
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 01.67 sec 3140 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags