#include "iostream"
#include "string"
#include "sstream"
using namespace std;
int main()
{
int TestCase;
cin >> TestCase;
while (TestCase--)
{
int N;
cin >> N;
string str = "";
for (int i = 1; i <= N; i++)//将输入的数字转换为字符串来统计其出现的次数
{
string temp;
stringstream s;
s << i;
s >> temp;
str += temp;
}
int count[10] = {0};//存储数字出现的次数!
int size = str.size();
for (int i = 0; i < size; i++)//统计字符串中数字出现的次数
{
switch(str[i])
{
case '0' : count[0]++;
break;
case '1' : count[1]++;
break;
case '2' : count[2]++;
break;
case '3' : count[3]++;
break;
case '4' : count[4]++;
break;
case '5' : count[5]++;
break;
case '6' : count[6]++;
break;
case '7' : count[7]++;
break;
case '8' : count[8]++;
break;
case '9' : count[9]++;
break;
}
}
for (int i = 0; i < 10; i++)
{
if (i != 0)
cout << " ";
cout << count[i];
}
cout << endl;
}
}
sicily 1608
最新推荐文章于 2017-12-20 22:06:30 发布