很疑惑,样例是对的,也尝试了其他数字,但是提交就全wa

P2669 [NOIP2015 普及组] 金币

zifeiyv @ 2024-11-04 23:13:11

include <stdio.h>

int main()
{
    int k,s;
    scanf("%d",&k);
    int d = 0;
    int i = 0;
    while(k>d)//算出k是几组数的和
    {
        i++;
        d += i;
    }
    for(int j = 1;j<=i;j++)//计算整组的金币数量(假设全部都是整组)
    {
        s += j * j;
    }
    if((d-k)!=0)
    {
        s = s-i*(d-k);  //减去多余的金币数量
    } 
    printf("%d",s);
   return 0;
}

by yuanminQAQ @ 2024-11-05 18:18:09

同上,我和你思路几乎一模一样


by imx2g @ 2024-11-24 17:29:52

include上没#编译都过不了


by imx2g @ 2024-11-24 17:33:34

除此之外,s没初始化,初始化为0后可以ac


|