7 solutions

  • 1
    @ 2025-1-18 9:28:02
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n,h=1;
    	bool flag=0;
    	cin>>n;
    	int k;
    	while(cin>>k)
    	{
    		for(int j=1;j<=k;j++)
    		{
    			cout<<flag;
    			h++;
    			if(h>n)
    			{
    				cout<<endl;
    				h=1;
    			}
    		}
    		flag=!flag;
    	}
    	return 0;
    }
    
    • @ 2025-1-18 9:29:25

      题目不是保证不会超范围吗,直接while cin 就行

  • 0
    @ 2023-12-23 12:41:19
    #include<iostream>
    using namespace std;
    int n,Map[40005],Full,p=0;
    bool Key;
    int main(){
        cin>>n;
        while(cin>>Full){
            int i;
            for(i=p;i<p+Full;i++) Map[i]=Key;
            p=i,Key=!Key;
        }
        p=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<Map[p];
                p++;
            }
            cout<<endl;
        }
        return 0;    
    }
    
    • 0
      @ 2023-11-4 15:28:22
      using namespace std;
      int main() {
      	int a=0,sum=0,i=1;
       	int m[105];
       	cin>>m[0];
       	while(cin>>m[i]){
       		a=i;
       		i+=1;
      	}
      	for(int i=1;i<=a;i++){
      		
      		if(i%2==1){
      			for(int j=0;j<m[i];j++){
      				cout<<'0';
      				sum+=1;
      				if(sum%m[0]==0){
      					cout<<endl;
      				}
      			}
      		}
      		else{
      			for(int j=0;j<m[i];j++){
      				cout<<'1';
      				sum+=1;
      				if(sum%m[0]==0){
      					cout<<endl;
      				}
      			}
      		}
      	
      	}
          return 0;
      }
      
      
      • -1
        @ 2024-12-13 13:43:37
        
        #include<bits/stdc++.h>
        using namespace std;
        int n;
        char f = '0';
        int a;
        int sum = 0;
        int main()
        {
        	cin >> n;
        	while(cin >> a)
        	{
        		for(int j = 1; j <= a; j++)
        		{
        			if(sum == n)
        			{
        				cout << endl;
        				sum = 0;
        				
        			}
        			cout << f;
        			sum++;
        		}
        		if(sum == n)
        		{
        			cout << endl;
        			sum = 0;
        		}
        		if(f == '0')
        		{
        			f = '1';
        		}else
        		{
        			f = '0';
        		}
        	}	
        	
        	
        	
        	return 0;
        }
        
        
        
        • -1
          @ 2023-10-28 22:05:50
          本题思路:
          将所有的0,1先存到一个字符串里
          再通过循环输出,换行是通过余数判断
          

          所以代码:

          #include<iostream>
          #include<string>
          using namespace std;
          int main()
          {
           int n;
           cin>>n;//输入
           string a;
           int x,s=1;
           bool no=false;
           while(s<=n*n)//是否超过n*n范围
           {
            cin>>x;//输入
            for(int i=0;i<x;i++)//输入的次数
            {
             if(no==false)//连接字符
              a+='0';
             else
              a+='1';
            }
            no=!no;//反转
            s+=x;
           }
           for(int i=1;i<n*n+1;i++)
           {
            cout<<a[i-1];//输出
            if(i%n==0 && i!=n*n)//是否要换行
             cout<<endl;//换行
           }
           return 0;//完结散花!
          }
          
          • -3
            @ 2023-10-24 20:55:12

            #include using namespace std; int main(){ int n,s=0,t,r=0;//s控制换行,r控制输出0或1 cin>>n; while(cin>>t){ r++; if(r%2==1){

            for(int i=1;i<=t;i++){
                    
                    if(s==n){
                        cout<<endl;
                        s=0;
                    }
                    cout<<0;
                    s++;
                }
                }
                if(r%2==0){
                    
                    for(int i=1;i<=t;i++){
                        if(s==n){
                        cout<<endl;
                        s=0;
                    }
                    cout<<1;
                    s++;
                }
                }
                    
                
            }
            return 0;
            

            }

            • -3
              @ 2023-10-24 20:53:28

              本题思路是将矩阵一次性输出,后换行将其重新变为矩阵......

              #include <bits/stdc++.h>
              using namespace std;
              int main(){
                  bool ch=0;//题目说全为0或1,用布尔型
                  int n,t;//n为矩阵大小
                  cin>>n;
                  int ges=n;//将个数定义为n个,从后往前数
                  while(cin>>t){//当输入t时
                      for(int i=1;i<=t;i++){
                          if(ges==0){//从后往前数到t=0时(从n数到0,相当于一行输出后换行),换行
                              cout<<"\n";
                              ges=n;//重新将个数变为一行的个数,从头开始重数一行
                          }
                          ges--;//个数依次减少,想一想为什么要放到这里
                          cout<<ch;//输出
                      }
                      ch=!ch;//想一想这里是什么意思,重点
                  }
                  return 0;
              }
              

              //ch=!ch将ch取反,即将1变为0或0变为1

              • 1

              Information

              ID
              928
              Time
              1000ms
              Memory
              125MiB
              Difficulty
              6
              Tags
              # Submissions
              139
              Accepted
              38
              Uploaded By