为啥啥都输出不出来,EOF咋用

P1319 压缩技术

yanghaoyu123 @ 2024-11-18 21:36:52

#include <iostream>
#include<cstdio>
using namespace std;
int main(){
    int n;
    cin>>n;
    int x=0;
    int ss=0;
    int a=0;
    while(scanf("%d",a) != EOF){
        if (x%2==0){
            for (int i=0;i<a;i++){
                if(ss%n==0){
                    cout<<endl;
                }
                cout<<0;
                ss+=1;
            }
        }
        else{
            for (int i=0;i<a;i++){
                if(ss%n==0){
                    cout<<endl;
                }
                cout<<1;
                ss+=1;
            }
        }
        x+=1;
    }

    return 0;
}

by mayike @ 2024-11-18 21:40:13

@yanghaoyu123

scanf("%d",a) 可还行?


by 13389660737ljx @ 2024-11-18 21:40:44

我记得是~scanf("%d",&a) != EOF

要取非,而且要加取地址符


by yanghaoyu123 @ 2024-11-18 21:42:39

@13389660737ljx@mayike谢谢


by yanghaoyu123 @ 2024-11-18 21:44:34

@13389660737ljx@mayike为啥停不下来,死循环


by yanghaoyu123 @ 2024-11-18 21:45:15

#include <iostream>
#include<cstdio>
using namespace std;
int main(){
    int n;
    cin>>n;
    int x=0;
    int ss=0;
    int a=0;
    while(scanf("%d",&a)!=EOF){
        if (x%2==0){
            for (int i=0;i<a;i++){
                if(ss!=0 && ss%n==0){
                    cout<<endl;
                }
                cout<<0;
                ss+=1;
            }
        }
        else{
            for (int i=0;i<a;i++){
                if(ss%n==0){
                    cout<<endl;
                }
                cout<<1;
                ss+=1;
            }
        }
        x+=1;
    }

    return 0;
}

by mayike @ 2024-11-18 21:45:16

@yanghaoyu123 ctrl Z


by yanghaoyu123 @ 2024-11-18 21:45:59

@mayike写一下呗,实在是不会


by mayike @ 2024-11-18 21:48:51

@yanghaoyu123 先运行,然后输入。输入完后在键盘上按 ctrl,然后 按 Z,然后换行


by yanghaoyu123 @ 2024-11-18 21:49:41

@mayike提交洛谷之后20pts,其他全红


by mayike @ 2024-11-18 21:50:30

@yanghaoyu123 那与我无关了,反正你的代码可以运行和正常输出了


| 下一页