c++全WA求助

P2669 [NOIP2015 普及组] 金币

siyu0816 @ 2022-09-13 19:10:56

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n=0,s=0,a=0,l=1;
    cin>>k;
    for(int i=0;;i++)
    {
            if(n==k)
            {
                cout<<s<<endl;
            }
            else
            {
                a+=i;
                s++;
            }
        i++;
    }
    return 0;
}

by Katz @ 2022-09-13 19:12:42

你死循环了啊


by AirQwQ @ 2022-09-13 19:13:26

你的n,压根没变啊


by wasmhdyn1 @ 2022-09-13 19:15:26

???


by siyu0816 @ 2022-09-13 21:14:56

#include <iostream> 
using namespace std;
int n,q,c,s;
int main()
{
    cin>>n;
    c=q=1;  
    for(int i=1;i<=n;i++)   
    {
        s=s+c;  
        q--;    
        if(q==0)    
        {
            c++;    
            q=c;    
        }
    }
    cout<<s;
    return 0;
}

by lizhehao @ 2022-10-07 12:43:51

#include<iostream>
using namespace std;
void haha(int times){
    int sum=0,a=1,i=1;
        for(i=1;i<=times;i++){
        times-=i;
        sum+=a*a;
        a++;
    }   
    cout<<sum+times*a;
}
int main(){
    int times,sum=0,a=1,i=1;
    cin>>times;
    haha(times);
    return 0;
}

by shuyuan2016 @ 2022-12-25 20:42:48

#include <iostream> 
using namespace std;
int n,q,c,s;
int main(){
    cin>>n;
    c=q=1;  
    for(int i=1;i<=n;i++){
        s+=c;
        q--;
        if(q==0)
        {
            c++;
            q=c;
        }
    }
    cout<<s;    
    return 0;   
}

by GGmaxgch @ 2023-02-24 21:39:43

......


|