5 条题解

  • 1
    @ 2025-6-15 10:56:51
    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    signed main() 
    {
    	int n,x;
    	cin>>n>>x;
    	int i,j;
    	int cnt=0;
    	for(i=1;;i++)
    	{
    		for(j=1;j<=n;j++)
    		{
    			cnt++;
    			if(cnt<10)cout<<' ';
    			cout<<cnt<<' ';
    			if(cnt>=x)break;
    		}
    		cout<<endl;
    		if(cnt>=x)break;
    	}
    }
    
    • 0
      @ 2024-12-27 21:20:16
      #include<bits/stdc++.h>
      using namespace std;
      signed main(){
      	int n,m;
      	cin>>n>>m;
      	for(int i=1;i<=m;i++){
      		cout<<setw(2)<<i<<" ";
      		if(i%n==0)cout<<"\n";
      	}
      }
      
      • 0
        @ 2024-12-22 19:20:58

        cout 的时候加个 setw 直接秒杀。

        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int a,b;
        	cin>>a>>b;
        	int c=b%a;
        	int ans=1;
        	for(int i=1;i<=b/a;i++)
        	{
        		for(int j=1;j<=a;j++)
        		{
        			cout<<setw(2)<<ans<<' ';
        			ans++;
        		}
        		cout<<endl;
        	}
        	for(int i=1;i<=c;i++)
        	{
        		cout<<setw(2)<<ans<<' ';
        		ans++;
        	}
        	return 0;
        }
        
        • 0
          @ 2024-12-22 11:27:17

          直接用setw设置域宽即可。

          #include<bits/stdc++.h>
          #define int long long
          #define INF 0x3f3f3f
          using namespace std;
          int x,y,ans;
          signed main(){
          	cin>>x>>y;
          	for(int i=1;i<=y;i++){
          		ans++;
          		cout<<setw(2)<<i<<" ";
          		if(ans%x==0)cout<<"\n";//记得中间要换行
          	}
          	return 0;
          }
          
          • 0
            @ 2024-12-22 11:03:52

            C++ :

            #include <bits/stdc++.h>
            using namespace std;
            int main(){
            	//freopen("pfz.in","r",stdin);
            	//freopen("pfz.out","w",stdout);
            	int m,n;
            	cin>>m>>n;
            	for(int i=1;i<=n;i++){
            		cout.width(2);
            		cout<<i<<" "; 
            		if(i%m==0){
            			cout<<endl; 
            		}	
            	}
            	return 0;
            	fclose(stdin);
            	fclose(stdout);
            }
            

            Python :

            # coding=utf-8
            x=input().split()
            a=int(x[0])
            b=int(x[1])
            ans=0
            for i in range(1,b+1):
                ans=ans+1
                ans=ans%a
                if i<10:
                    print(" ",end='')
                print(i,end=' ')
                if ans==0:
                    print()
            
            • 1

            信息

            ID
            9
            时间
            1000ms
            内存
            128MiB
            难度
            2
            标签
            递交数
            66
            已通过
            39
            上传者