为什么不管n为任何值输出的y都是1

P1319 压缩技术

qew12312 @ 2023-01-09 10:43:40

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n,sum=0,sum1=0,y,u;
    cin>>n;
    int a[100];
    for(int y=1;sum<(n*n);)
    {
    cin>>a[y];
    sum+=a[y];
    y++;}cou<<y;
        return 0;
}

by Joker_lazydoghead @ 2023-01-09 10:45:14

cou<<y??????


by Joker_lazydoghead @ 2023-01-09 10:46:53

你都定义了y还int y=1干嘛

改成for(y=1;sum<(n*n))


by Loser_Syx @ 2023-01-09 10:46:57

@qew12312 请问楼主是不会复制粘贴吗?cou<<y都出来了


by Loser_Syx @ 2023-01-09 10:48:43

@qew12312 楼主是交错题了吗,总感觉这两个东西搭不上边啊


by qew12312 @ 2023-01-09 10:56:11

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n,sum=0,sum1=0,y,u;
    cin>>n;
    int a[100];
    for(y=1;sum<n*n;y++)
    {
    cout<<a[y];
    sum+=a[y];}
    for(int t=1;t<=y;t++){
        for(u=1;u<=a[t];u++){sum1+=u;
            if(t%2!=0) cout<<"0";
            else cout<<"1";
            if(sum1%7==0) cout<<endl;
        }
    }
        return 0;
}   
    //这是原码,刚才只是拿来调试的

by qew12312 @ 2023-01-09 10:56:52

@lazy_doghead 改了还是不对诶


by Joker_lazydoghead @ 2023-01-09 10:58:32

for(y=1;sum<n*n;y++)
    {
    cout<<a[y];
    sum+=a[y];}

???

不应该是cin吗


by qew12312 @ 2023-01-09 11:15:28

改了cin还是不对,诶


|