paranteze (recursivitate indirecta)
Last Updated: Dec 22 2014 22:54, Started by
jamesbond1975
, Dec 22 2014 22:38
·
0
#1
Posted 22 December 2014 - 22:38
Buna,
Ma poate ajuta cinvea la urmatoarea problema http://varena.ro/problema/paranteze3. Multumesc Codul care l-am scris este : #include <stdio.h> #include <stdlib.h> FILE *fi, *fo; int first, er, max, s; int S() { int s=0; if(first=='{') { first=fgetc(fi); s=S()+1; if(max<s) max=s; if(first=='}') first=fgetc(fi); else er=1; S(); } else { if(first=='(') { first=fgetc(fi); if(max<s) max=s; s=S()+1; if(first==')') first=fgetc(fi); else er=1; S(); } } return max; } int main() { int a; fi = fopen("paranteze3.in","r"); fo = fopen("paranteze3.out","w"); first=fgetc(fi); a=S(); if(first!='\n') er=1; if(er==1) fprintf(fo,"-1\n"); else fprintf(fo,"%d",a); fclose(fi); fclose(fo); return 0; } |
#2
Posted 22 December 2014 - 22:54
explica in cuvinte ce vrea sa faca codul tau
edit si nu-mi spune ca vrea sa rezolve problema pentru ca este destul de clar ca nu o face Edited by MarianG, 22 December 2014 - 22:55. |
Anunturi
Bun venit pe Forumul Softpedia!
▶ 0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users