Logic, Analysis, and Computation

宠辱不惊 静观窗前花开花落 去留无意 闲看天上云卷云舒

导航

<2009年5月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

统计

公告

如需转载, 请注明出处。

常用链接

留言簿

随笔分类

随笔档案

文章档案

I/O performance

搜索

最新评论

Programming note: problems related to couting the pairs of {}

今天继续做作业, 遇到 couting  {} 的问题, 自己的解决方法太笨拙, 把自己总结的别人的方法记录一下:


int a; //record the pos of '{'

int b = a; //record the pos of the matched '}'

int open = 1//record the number of {}

while ( open > 0 ) {
    
    b
++;
    
if ( s[b] == '}' ) {
        open
--;
    }
 
    
else if ( s[b] == '{' ) {
        open
++;
    }

  
}

 

posted on 2009-05-27 02:31 小学毕业生 阅读(169) 评论(0)  编辑 收藏 引用 所属分类: Programming


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理