设为首页 加入收藏

TOP

hdu 1274
2014-11-23 20:16:34 来源: 作者: 【 】 浏览:3
Tags:hdu 1274

解题思路:

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< 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 1051 Wooden Sticks 下一篇hdu 4643 GSM 计算几何 - 点线关..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C 内存管理 | 菜鸟教 (2025-12-26 20:20:37)
·如何在 C 语言函数中 (2025-12-26 20:20:34)
·国际音标 [ç] (2025-12-26 20:20:31)
·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)