3 条题解

  • 6
    @ 2023-9-24 14:59:14
    #include <bits/stdc++.h>
    using namespace std;
    int n, num[25], a, b, c, d;
    int main()
    {
    	cin >> n;
    	for (int i = 1; i <= n; i++)
    		cin >> num[i];
    	cin >> a >> b >> c >> d;
    	for (int i = a, j = c; i <= b, j <= d; i++, j++)
    		swap(num[i], num[j]);
    	for (int i = 1; i <= n; i++)
    		cout << num[i] << " ";
    	return 0;
    }
    

    短小精悍的代码

    • 0
      @ 2023-4-14 22:45:08

      直接硬钢

      #include<bits/stdc++.h>
      using namespace std;
      int n,a[22],x1,x2,y3,y2;
      bool x3,y4;
      int main()
      {
          cin>>n;
          for (int i=1;i<=n;i++)
              cin>>a[i];
          cin>>x1>>x2>>y3>>y2;
          for (int i=1;i<=n;i++)
          {
              if (i==x1&&!x3)
              {
                  for (int j=y3;j<=y2;j++)
                      cout<<a[j]<<" ";
                  i=x2;
                  x3=1;
                  continue;
              }
              if (i==y3&&!y4)
              {
                  for (int j=x1;j<=x2;j++)
                      cout<<a[j]<<" ";
                  i=y2;
                  y4=1;
                  continue;
              }
              cout<<a[i]<<" ";
          }
          return 0;
      }
      • 0
        @ 2023-1-29 14:07:03
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int a[30],n,x1,x2,y1,y2;
        	cin >> n;
        	for(int i = 1; i <= n; i++) cin >> a[i];
        	cin >> x1 >> x2;
        	cin >> y1 >> y2;
        	for(int i = x1,j = y1; i <= x2, j <= y2; i++,j++){
        		swap(a[i],a[j]);
        	}
        	for(int i = 1; i <= n; i++) cout << a[i] << " ";
        	return 0;
        }
        
        
        • 1

        信息

        ID
        171
        时间
        1000ms
        内存
        16MiB
        难度
        1
        标签
        递交数
        67
        已通过
        54
        上传者