码迷,mamicode.com
首页 >  
搜索关键字:并验证所有的花括号都正确的成对出现。    ( 6个结果
编写一个程序,它从标准输入(终端)读取C源代码,并验证所有的花括号都正确的成对出现。
#include<stdio.h> intmain() { intcou=0; charch; while((ch=getchar())!=‘\n‘) { if(ch==‘{‘) cou++; elseif(ch==‘}‘) { if(cou==0) printf("匹配不成功!"); cou--; } } if(cou==0) printf("匹配成功!"); else printf("匹配不成功!"); return0; }
分类:其他好文   时间:2015-10-31 01:42:54    阅读次数:119
一道验证花括号匹配的编程题
//编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现 #include<stdio.h> intmain() { intch=0; intcount=0; while((ch=getchar())!=EOF) { if(ch==‘{‘) count++; elseif((ch==‘}‘)&&(count==0)) { printf("匹配不成功!\n");..
分类:其他好文   时间:2015-10-22 19:38:32    阅读次数:225
C语言:编写一个程序,它从标准输入(终端)读取C源代码,并验证所有的花括号都正确的成对出现
#include<stdio.h> intmain() { charch; intcount=0; while((ch=getchar())!=EOF) { if(ch==‘{‘) { count++; } elseif(ch==‘}‘) { if(count==0) { printf("不成功匹配\n"); } else { count--; } } } if(count==0) { printf("成功匹配!\n"); }..
分类:编程语言   时间:2015-10-10 20:12:30    阅读次数:143
编写一个程序,它从标准输入(终端)读取C源代码,并验证所有的花括号都正确的成对出现。
#include<stdio.h> intmain() { intcount=0; charch; while((ch=getchar())!=EOF) { if(ch==‘{‘) { count++; } elseif(ch==‘}‘) { if(count==0) { printf("匹配不成功\n"); } else { count--; } } } if(count==0) ..
分类:其他好文   时间:2015-10-10 18:39:29    阅读次数:109
从标准输入读取C源代码,并验证所有的花括号都正确的成对出现
#include<stdio.h>#include<process.h>intmain(){ charc=0; intcount=0; while((c=getchar())!=EOF) { if(c==‘{‘) { count++; } elseif(c==‘}‘&&count==0) { printf("花括号不匹配!"); return0; } elseif(c==‘}‘&&count!=0) { co..
分类:其他好文   时间:2015-09-21 19:45:03    阅读次数:153
编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现
(三种if的情况考虑完整,注意解决问题的思想)#include<stdio.h>intmain(){intcount=0;charch;while((ch=getchar())!=EOF)//直到出现文件结束标志,不再进入循环{if(ch==‘{‘){count++;}if(ch==‘}‘&&count==0)//前无‘{‘,而后有‘}‘,即不匹配{printf("不匹配\n");r..
分类:其他好文   时间:2015-09-19 22:48:57    阅读次数:264
6条  
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!