没学数组,这题怎么做?

P1046 [NOIP2005 普及组] 陶陶摘苹果

cxq_com @ 2022-01-25 17:14:05

没学数组,这题怎么做?


by _Haoomff_ @ 2022-01-25 17:14:57

sorry,没法做


by Sol1 @ 2022-01-25 17:15:02

去学


by Misaka_Mik0t0 @ 2022-01-25 17:15:27

去学数组再做,花不了你多长时间。


by cxq_com @ 2022-01-25 17:16:31

@kinnikinnick233@_Solowing_ClCN@L_YALONG谢谢


by rui_er @ 2022-01-25 17:16:34

用 11 个变量存一下


by Scene @ 2022-01-25 17:17:31

建议10个变量10个判断


by fake_ @ 2022-01-25 17:18:21

无数组:

#include<bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c,d,e,f,g,h,i,j,k;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j>>k;
    int num=0;
    if(a<=k+30) num++;
    if(b<=k+30) num++;
    if(c<=k+30) num++;
    if(d<=k+30) num++;
    if(e<=k+30) num++;
    if(f<=k+30) num++;
    if(g<=k+30) num++;
    if(h<=k+30) num++;
    if(i<=k+30) num++;
    if(j<=k+30) num++;
    cout<<num;
}

不要慌着抄,老实学习


by huangzitai @ 2022-01-25 17:29:59

#include<bits/stdc++.h>

using namespace std;

int x, k, ans = 0;

vector<int> a;

int main () {
    for (int i = 1; i <= 10; i++) {
        cin >> x;
        a.push_back(x);  
    }
    cin >> k;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] <= k + 30) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

by batmanzhan @ 2022-02-26 10:03:10

去学吧,不费时。 或10个if判断


by batmanzhan @ 2022-02-26 10:43:12

去学吧,不费时


| 下一页