大佬们救命,刚学if语句,用C语言暴力写出来的,在vs22上可以跑

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

XTTian @ 2023-10-23 22:56:18

![]("C:\Users\Tt\Pictures\Screenshots\屏幕截图 2023-10-23 222803.png")```c

include<stdio.h>

int main() { int a = 0; int b = 0; int c = 0; int d = 0; int e = 0; int f = 0; int g = 0; int h = 0; int i = 0; int j = 0; int A = 0; int num = 0; scanf("%d %d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j); scanf("%d", &A); if (A >= a) { num = num + 1; } if (A >= b) { num = num + 1; } if (A >= c) { num = num + 1; } if (A >= d) { num = num + 1; } if (A >= e) { num = num + 1; } if (A >= f) { num = num + 1; } if (A >= g) { num = num + 1; } if (A >= h) { num = num + 1; } if (A >= i) { num = num + 1; } if (A >= j) { num = num + 1; } printf("%d", num); return 0; }


by zzr1208 @ 2023-10-23 22:59:47

大哥,你这一堆乱码


by hyy114514 @ 2023-10-23 23:02:01

lz原代码

#include <stdio.h>

int main() {
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    int e = 0;
    int f = 0;
    int g = 0;
    int h = 0;
    int i = 0;
    int j = 0;
    int A = 0;
    int num = 0;
    scanf("%d %d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j);
    scanf("%d", &A);
    if (A >= a) {
        num = num + 1;
    }
    if (A >= b) {
        num = num + 1;
    }
    if (A >= c) {
        num = num + 1;
    }
    if (A >= d) {
        num = num + 1;
    }
    if (A >= e) {
        num = num + 1;
    }
    if (A >= f) {
        num = num + 1;
    }
    if (A >= g) {
        num = num + 1;
    }
    if (A >= h) {
        num = num + 1;
    }
    if (A >= i) {
        num = num + 1;
    }
    if (A >= j) {
        num = num + 1;
    }
    printf("%d", num);
    return 0;
}

by zzr1208 @ 2023-10-23 23:02:03

陶陶有个30厘米高的板凳

仔细读题


by zzr1208 @ 2023-10-23 23:02:37

我查到记录了


by wwwidk1234 @ 2023-10-23 23:13:22

![]("C:\Users\Tt\Pictures\Screenshots\屏幕截图 2023-10-23 222803.png")

我们看不到你电脑的图片,请使用洛谷图床上传。

这段代码错因:陶陶有个 30 厘米高的板凳。你的高度没有加 30 \operatorname{cm}

建议 A+=30;

另外,下次代码要用Markdown了。(格式手册here)

我的代码是用优先队列过去的


#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int suffm=0,sym=1;
    char chr=getchar();
    while(chr<'0'||chr>'9'){if(chr=='-') sym=-1;chr=getchar();}
    while(chr>='0'&&chr<='9'){suffm=(suffm<<3)+(suffm<<1)+(chr^48);chr=getchar();}
    return suffm*sym;
}
inline void write(int suffm)
{
    if(suffm<0){putchar('-');suffm=-suffm;}
    if(suffm>9) write(suffm/10);
    putchar(suffm%10+48);
}
priority_queue<int,vector<int>,greater<int>> q;
signed main()
{
    for(int i=0;i<10;i++) q.push(read());
    int cnt=0;
    int maxh=read()+30;
//  while(!q.empty()) {cout<<q.top()<<" ";q.pop();}
    while(1)
    {
        int tp=q.top(); q.pop();
        if(tp>maxh) break;
        cnt++;
    }
    write(cnt);
    return 0;
}

by XTTian @ 2023-10-24 15:35:33

@wwwidk1234 谢谢,问题已解决,下次一定记得用Markdowm,第一用洛谷提问,还不太会


by XTTian @ 2023-10-24 15:35:59

@zzr1208 谢谢,问题已解决


|