PTA7-9 minimum number of questions
Question type
Simplicity
Realization idea
- First use an array to store the read data, the data is the number of 0-9
- Enter the loop, pay attention to start from 1 first, because zero is skipped
- Find the first non-zero element with a non-zero number
- Enter the loop, output the element
Implementation code
#include <iostream>
using namespace std;
int main()
{
int num[10];
for (int i = 0; i < 10; i++)
{
cin >> num[i];
}
for (int i = 0; i < 10; i++)
{
if (num[i] != 0 && i != 0)
{
cout << i;
num[i]--;
break;
}
}
for (int i = 0; i < 10; i++)
{
for (int k = 0; k < num[i]; k++)
{
cout << i;
}
}
return 0;
}
Error-prone
If you don’t read the question carefully, just output the first non-zero element once. This point is the first and last test point of the question.