CCF201609-2 train ticket compilation error
19.09.06 When using VS2017 to do this question, submitting it to the CCF platform always shows a compilation error.
The selected C++11 standard, the correct result can be obtained on VS, but the CCF platform shows a compilation error.
Later, it was found that it might be a problem with the memset function. After using the fill function, the problem was solved and a full score was obtained.
#include<cstdio>
#include<algorithm>
using namespace std;
int arr[21];
bool hashTable[105] = {
false };
bool flag = false;
int main()
{
int n, buy;
scanf("%d", &n);
//memset(arr, 0, sizeof(arr));
fill(arr, arr + 21, 0);
for (int i = 0; i < n; i++)
{
scanf("%d", &buy);
for (int j = 0; j < 20; j++)
{
if ((5 - arr[j]) >= buy)
{
flag = true;
int temp = arr[j];
for (int x = 0; x < buy; x++)
{
int r = 5 * j + 1 + temp + x;
if (x != buy - 1)
printf("%d ", r);
else
printf("%d\n", r);
hashTable[r] = true;
arr[j]++;
}
break;
}
}
if (flag==false)
{
for (int v = 1; v < 101; v++)
{
if (buy > 0)
{
if (hashTable[v] == false)
{
if (buy != 1)
printf("%d ", v);
else if (i != n - 1)
printf("%d\n", v);
else
printf("%d", v);
hashTable[v] = true;
int m = v / 5;
arr[m]++;
buy--;
}
}
else
break;
}
}
flag = false;
}
return 0;
}
As shown in the above code, after masking the memset function and replacing it with the equivalent fill function, the successful program is submitted with full marks.