#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char brackets[20];
int frequency[100];
for (int i = 0; i < 100; i++)
frequency[i] = 0;
printf("the array: ");
scanf("%s", brackets);
for (char ch = '!'; ch <= '}'; ch++)
{
for (int i = 0; i < strlen(brackets) && ok1; i++)
{
if (ch == brackets[i])
frequency[ch-'0']++; // we keep increase the character position frequency.
}
}
int ok = 1;
int a[100], l=0;
for (int i = 0; i < 100; i++)
if (frequency[i] > 0)
{
printf("frec %d appears on %d\n", frequency[i], i);
a[l] = frequency[i];
l++;
}
for (int i = 0; i < l-1; i++)
{
printf("%d ", a[i]);
if (a[i] != a[i + 1])
ok = 0;
}
if (ok)
printf("yes");
else
printf("no");
_getch();
}
大家好, 我正在从The C Programming Language学习C,我必须解决一个告诉我基本语法错误的问题。我决定使用频率向量来跟踪括号s.a()[]。我面临的问题是,如何才能弄清楚例如)是否在(。我尝试使用ASCII表,但是效果不好。第一点是要查看它们是否以相等的数字出现。现在我必须看看如果它们放置正确。 谢谢你们!