5 solutions

  • 3
    @ 2023-12-23 16:37:40

    相对简单的解法

    #include <bits/stdc++.h>
    using namespace std;
    char a,b='0';
    int n,ans[1000001],z=1;
    int main(){
    	while(cin>>a){
    	 	n++;
    	 	if(a==b) ans[z]++;
    	 	else ans[++z]++,b=a;
    	}
    	cout<<sqrt(n);
    	for(int i=1;i<=z;i++) cout<<" "<<ans[i];
    	return 0;
    }
    
    • 2
      @ 2023-10-6 10:38:44
      #include <bits/stdc++.h>
      using namespace std;
      char c,o = '0';int a[40005],n,idx;
      int main(int argc, char **argv){
      	while (cin >> c){
      		n++;
      		if (c == o){
      			a[idx]++;
      		}else{
      			o = c;
      			a[++idx]++;
      		}
      	}
      	int sqrt_n = sqrt(n);
      	printf("%d ",sqrt_n);
      	for (int i = 0;i <= idx;i++){	// 这里是 i=0 , 但是判断是 <=
      		printf("%d ",a[i]);
      	}
      	return 0;
      }
      
      • 1
        @ 2024-11-13 16:37:47
        #include<bits/stdc++.h>
        
        using namespace std;
        int a[100010];
        int main(){
        	string h;
          //字符串写法
        	int y=0;//行数
        	int k=0;//当前值
        	int u=0;//压缩数量
        	while(cin>>h){
        		y++;//记录n行
        		for(int i=0;i<h.size();i++){
        			if(h[i]-'0'+0==k){
        				a[u]++;
        			}else{
        				u+=1; 
        				a[u]++;
        				k=(k+1)%2;//变1或0
        			}
        		}
        	}
        	cout<<y<<" ";
        	for(int i=0;i<=u;i++){
        		cout<<a[i]<<" ";
        	}
        	//7 3 1 6 1 6 4 3 1 6 1 6 1 3
        	//7 3 1 6 1 6 4 3 1 6 1 6 1 3 7
        	return 0;
        } 
        
        • 0
          @ 2024-1-5 13:44:20
          #include<bits/stdc++.h>
          using namespace std;
          string a[40000];
          int u[75767];
          int b[40008];
          int main(){
          	int n,x=0,y=0,h=0,g;
          	int d=1;
          	bool s=0;
              cin>>a[0];
              g=a[0].size();
              
          	for(int i=1;i<=g-1;i++){
          		cin>>a[i];
          	}
          	int k=0;
          	for(int i=0;i<g;i++)
          	for(int j=0;j<g;j++){
          	u[k++]=a[i][j]-'0';
          	}
          	u[g*g] = u[g*g-1] == 0? 1 : 0;
          	for(int i=0;i<g*g+1;i++){	
          	if(u[i]==0){
          		x++;
          		if(y!=0){
          		b[d]=y;
          		y=0;
          		d++;
          		}
          		
          	}
          	else{
          		y++;
          		if(x!=0){
          		b[d]=x;
          		x=0;
          		d++;
          		}
          	}	
          	}
          	cout<<g<<" ";
          	if(u[1]==0){
          		for(int i=2;i<=d;i++){
          		cout<<b[i-1]<<" ";
          	}
          	}
          	else{
          		cout<<0<<" ";
          		for(int i=2;i<=d;i++){
          		cout<<b[i-1]<<" ";
          	}
          	}
          	
          }
          
          • -1
            @ 2023-10-2 10:04:33

            `

            #include <bits/stdc++.h>//luogu福利
            using namespace std;
            
            char a,b='0';//注意了:一定是赋值为'0';
            int n,ans[1000001],zz=1;//zz是指针的意思,我用来存储第几位
            
            int main()
            {
             while(cin>>a)
             {
             	n++;
             	if(a==b)
             		ans[zz]++;
             	else
             		ans[++zz]++,//等效于:zz=zz+1;ans[zz]++
             		b=a;//上面用 , 不用 ; 的原因是我没有打{ }
             }
             cout<<sqrt(n);//平方根,用到了<cmath>或者是<math.h>,也就是一行的行数
             for(int i=1 ; i<=zz ; i++)
                 cout<<" "<<ans[i];
            }
            
            • @ 2023-10-7 8:40:52

              写得太详细了太好了👀️

            • @ 2023-12-23 16:38:13

              跟我思路差不多

          • 1

          Information

          ID
          901
          Time
          1000ms
          Memory
          512MiB
          Difficulty
          6
          Tags
          # Submissions
          146
          Accepted
          41
          Uploaded By