hdu 1274

2014-11-23 20:16:34 · 作者: · 浏览: 4

解题思路:

f1:先对数字进行处理。然后判断接下来的是( ,还是字母。若是(则递归调用f1,若是字母则直接输出。

这道题传说中可以用容器来做,但是后来才去的是以下做法:

/* 
 * 1274_5.cpp 
 * 
 *  Created on: 2013年8月7日 
 *      Author: Administrator 
 * 
 *      章泽天,我的女神!!!! 
 */  
  
  
#include    
  
using namespace std;  
  
string str;  
int fun(int index){  
  
    char c ;  
    int k;  
    int e = 0;  
  
    for(c = str[index++] ; index < str.length() && c != ')' ; c  = str[index++]){  
  
        for( k = 0 ; isdigit(c) ; c = str[index++]){  
            k = 10*k + c - '0';  
        }  
  
        if(!k){  
            k = 1;  
        }  
  
        if( c == '('){  
            while(k--){  
                e = fun(index);  
            }  
  
            index = e;  
        }else{  
            while(k--){  
                cout<> t;  
    while(t--){  
        cin >> str;  
        fun(0);  
        cout<

using namespace std;

string str;
int fun(int index){

	char c ;
	int k;
	int e = 0;

	for(c = str[index++] ; index < str.length() && c != ')' ; c  = str[index++]){

		for( k = 0 ; isdigit(c) ; c = str[index++]){
			k = 10*k + c - '0';
		}

		if(!k){
			k = 1;
		}

		if( c == '('){
			while(k--){
				e = fun(index);
			}

			index = e;
		}else{
			while(k--){
				cout<> t;
	while(t--){
		cin >> str;
		fun(0);
		cout<