AceInfinity
Emeritus, Contributor
I think Visual Studio needs to upgrade their support for the newer C specifications. As far as I know it only provides support for C89... So when I went to write a little code in C for a programming challenge...
Note: For those of you interested in trying this problem on your own, ignore the following code below and attempt this first on your own: https://icpcarchive.ecs.baylor.edu/external/62/6242.pdf
I had to adopt those changes, and It caused quite a bit of grief..
Note: For those of you interested in trying this problem on your own, ignore the following code below and attempt this first on your own: https://icpcarchive.ecs.baylor.edu/external/62/6242.pdf
Code:
#include <stdio.h>
#include <stdlib.h>
int clean_scanf(long* n, long* k, long* q)
{
int result = scanf("%ld %ld %ld", n, k, q);
int ch; while ((ch = getc(stdin)) != EOF && ch != '\n');
return result;
}
int F(int n, int k, int q)
{
int ans;
int* nums;
int i, j = 0;
if (n >= 0 && n < k) return 1;
nums = (int*)malloc(k * sizeof(int));
for (i = k - 1; i >= 0; i--) nums[i] = 1;
for (i = 0; i < n; i++)
{
int sum = 0;
int x; for (x = 0; x < k; x++) sum += nums[x];
nums[j] = sum;
j = (j + 1) % k;
}
ans = nums[j];
free(nums);
return ans % q;
}
int main()
{
int caseNum = 0;
long n, k, q;
clean_scanf(&n, &k, &q);
while (n + k + q != 0)
{
int result = F(n, k, q);
printf("Case #%d: %ld\n", ++caseNum, result);
clean_scanf(&n, &k, &q);
}
printf("\n...");
getchar();
return 0;
}
I had to adopt those changes, and It caused quite a bit of grief..
Attachments
Last edited: