#include<stdio.h> int main() { char str[1000000]; while(scanf("%s",str)!=EOF) { int temp=0,ans=0; for(int i = 0; str[i]; i++) { if(str[i] == '(') { temp++; } else if(temp > 0) { temp--;//保证)前面有匹配的(的存在 ans += 2; } } printf("%d\n",ans); } return 0; }
#include<stdio.h> int main() { char str[1000000]; while(scanf("%s",str)!=EOF) { int temp=0,ans=0; for(int i = 0; str[i]; i++) { if(str[i] == '(') { temp++; } else if(temp > 0) { temp--;//保证)前面有匹配的(的存在 ans += 2; } } printf("%d\n",ans); } return 0; }
转载于:https://www.cnblogs.com/jianrenguo/p/6549326.html