#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <cstring>
using namespace std;
//#define PI 3.1415926
int main()
{
int a[10];
int m,n;
cin >> m >> n;
int first = 1;
char s[100] = {0};
for(int i = m;i <= n;++i)
{
sprintf(s,"%d",i);
for(int j = 0;j < strlen(s);++j)
a[(s[j]-'0')]++;
}
for(int i = 0;i < 10;++i)
{
if(first)
first = 0;
else cout <<" ";
cout << a[i];
}
return 0;
}
为什么把int a[10]放在main函数内部和放在main函数外边最造成输出结果不一样,这是为什么?在遇到时该怎么判断才能避免掉这种输出错误。