我在本地机器上没有收到任何错误,但是 codechef 和 ideone 给出了运行时错误代码
#include<stdio.h>
int main()
{
int n, m, i, x, j;
int a[n], b1, b2, b[n], c[m];
do
{
scanf("%d%d", &n, &m);
} while (!((1 <= n && n <= 100000) && (1 <= m && m <= 100000)));
for (i = 1; i <= n; i++)
{
do
{
scanf("%1d", &a[i]);
} while (!(0 <= a[i] && a[i] <= 9));
}
for (i = 1; i <= m; i++)
{
do
{
scanf("%d", &x);
} while (!(1 <= x && x <= n));
b1 = 0;
b2 = 0;
for (j = 1; j < x; j++)
{
b[j] = a[x] - a[j];
if (b[j] > 0)
b1 = b1 + b[j];
if (b[j] < 0)
b2 = b2 + b[j];
}
c[i] = b1 - b2;
}
for (i = 1; i <= m; i++)
printf("\n%d", c[i]);
return 0;
}