4 条题解

  • 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
          标签
          递交数
          49
          已通过
          32
          上传者