标签:c
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int main() { int i = 0, a = 0; int j = 0, b = 0; int count = 0; char arr1[50]; char arr2[20]; printf("请输入源代码:\n"); scanf("%s", arr1); for (i = 0; i < strlen(arr1); i++) { if (arr1[i] == ‘{‘ || arr1[i] == ‘}‘) { arr2[j] = arr1[i]; j++; } } arr2[j] = 0; for (i = 0; i < strlen(arr2) - 1; i++) for (j = i + 1; j < strlen(arr2); j++) { if (arr2[i] == ‘{‘ && arr2[j] == ‘}‘) { count++; break; } } if (strlen(arr2) % 2 != 0) { printf("匹配不成功\n"); } if ((strlen(arr2) % 2 == 0) && (count == (strlen(arr2) / 2))) { printf("匹配成功\n"); } if ((strlen(arr2) % 2 == 0) && (count != (strlen(arr2) / 2)) && count != 0) { printf("匹配不成功\n"); } if ((strlen(arr2) % 2 == 0) && count == 0) printf("无匹配字符\n"); system("pause"); return 0; }
本文出自 “Vs吕小布” 博客,请务必保留此出处http://survive.blog.51cto.com/10728490/1701748
标签:c
原文地址:http://survive.blog.51cto.com/10728490/1701748