69 条题解

  • 54
    @ 2022-8-9 19:32:19

    这一道题思维可以转个弯,可以先把不是x的值输出,最后再输出x,注意!要加空格!上代码~

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n, a[100], x;
        cin >> n; 
        for (int i=1;i<=n;i++)
            cin >> a[i];
        cin >> x;
        for (int i=1;i<=n;i++)
        {
            if (a[i] != x) cout << a[i] << " ";
        }
        cout << x;
        return 0;
    }
    
    • @ 2023-8-26 16:59:14

      老大好

    • @ 2023-8-30 9:36:52

      按照你的方法,如果输入在a[i]中存入两个一样的数会发生什么情况 比如说我存入: 8 1 7 5 6 9 8 7 2 7 会输出什么呢

  • 25
    @ 2022-12-23 15:16:26

    这里为大家整理了两种做法

    AC代码1

    #include <iostream>
    using namespace std;
    int main()
    {
        int a[100], n, x, y;
        cin >> n;
        for (int i = 0; i < n; i++)
        {
        	cin >> a[i];
    	}
    	cin >> x;
    	for (int i = 0; i < n; i++)
        {
    		if (i + 1 != x)
            {
    			cout << a[i] << " ";
    		}
            else
            {
    		    y = a[i];	
    		}
    	}
        cout << y << endl;
        return 0;
    }
    

    AC代码2

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n, i, x;
    	cin >> n;
    	int a[n];
    	for (i = 0; i < n; i++)
        {
    		cin >> a[i];
    	}
    	cin >> x;
    	for (i = x; i <= n - 1; i++)
        {
    		int t = a[i - 1];
    		a[i - 1] = a[i];
    		a[i] = t;
    	}
    	for (i = 0; i < n; i++)
        {
    		cout << a[i] << " ";
    	}
    	return 0;
    }
    
    • @ 2024-2-1 18:10:25

      你好,你上面又有一个老大

    • @ 2024-2-1 18:16:33

      AC代码一不应该是这样的吗↓

      #include
      using namespace std;
      int main()
      {
          int a[100], n, x, y;
          cin >> n;
          for (int i = 0; i < n; i++)
          {
          	cin >> a[i];
      	}
      	cin >> x;
      	for (int i = 0; i < n; i++)
          {
      		if (i + 1 != x)
              {
      			cout << a[i] << " ";
      		}
              else
              {
      		    y = a[i];	
      		}
      	}
          cout << y << " ";
          return 0;
      }
      
    • @ 2024-2-1 18:31:44

      第一行我没写完整,你自己改一下

  • 13
    @ 2022-8-21 13:45:34

    我尽力了,只能这么写了

    #include<iostream>
    using namespace std;
    
    int main()
    {
        int a,x,n[10];
        cin>>a;
    
        for(int i=0;i<a;i++)
        {
            cin>>n[i];
        }
        cin>>x;
        for(int i=x;i<a;i++)
        {
            cout<<n[i]<<" ";
        }
        cout<<n[x-1];
    
        return 0;
    }
    
  • 6
    @ 2023-8-17 11:49:38
    #include <iostream>
    using namespace std;
    int main()
    {
        int n, a[11], x;
        cin >> n; 
        for (int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        cin>>x;
        for (int i=0;i<x-1;i++)
        {
            cout<<a[i]<<" ";
        }
        for (int i=x;i<n;i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<x;
        return 0;
    }
    
    • @ 2023-8-17 11:51:39

      绝对好用而且超级好理解

  • 6
    @ 2023-8-8 9:47:57
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n, a[100], x;
        cin >> n; 
        for (int i=1;i<=n;i++)
            cin >> a[i];
        cin >> x;
        for (int i=1;i<=n;i++)
        {
            if (a[i] != x) cout << a[i] << " ";
        }
        cout << x;
        return 0;
    }
    

    一手交赞,一手交代码。

    • 3
      @ 2023-8-17 15:13:55
      //已经AC,放心食用!!!( ̄▽ ̄)"
      #include <iostream>
      using namespace std;
      int main()
      {
          int n, a[11], x;
          cin >> n; 
          for (int i=0;i<n;i++)
          {
              cin>>a[i];
          }
          cin>>x;
          for (int i=0;i<x-1;i++)
          {
              cout<<a[i]<<" ";
          }
          for (int i=x;i<n;i++)
          {
              cout<<a[i]<<" ";
          }
          cout<<x;
          return 0;
      }
      //编写不易,可以给先我点赞再溜吗!,,ԾㅂԾ,,
      
      • 2
        @ 2023-8-26 16:01:02
        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            int n, a[100], x;
            cin >> n; 
            for (int i=1;i<=n;i++)
                cin >> a[i];
            cin >> x;
            for (int i=1;i<=n;i++)
            {
                if (a[i] != x) cout << a[i] << " ";
            }
            cout << x;
            return 0;
        }
        
        • 2
          @ 2023-8-16 10:28:28
          #include <iostream>
          using namespace std;
          int main()
          {
              int n,a[100],x,m = 0;
              cin >> n;
              for (int i = 0;i < n;i++)
              {
                  cin >> a[i];
              }
              cin >> x;
              m = a[x - 1];
              for(int i = 0;i < n - 1;i++)
              {
                  a[i] = a[i + 1];
                  cout << a[i] << " ";
              }
              cout << m;
              return 0;
          }
          
          • 1
            @ 2024-1-24 20:46:16

            这道题算简单的,在输出前先判断一下是不是要最后输出的数,如果是直接用continue跳过,最后输出那个数。(代码AC过的)

            #include <iostream>
            using  namespace std;
            int main()
            {
                int n,x;
                cin>>n;
                int a[n];
                for (int i=0;i<n;i++)
                {
                    cin>>a[i];
                }
                cin>>x;
                for (int i=0;i<n;i++)
                {
                    if (a[i]==x)
                    {
                        continue;
                    }
                    cout<<a[i]<<" ";
                }
                cout<<x;
                return 0;
            }
            
            • 1
              @ 2023-12-10 14:02:53
              #include <iostream>
              using namespace std;
              int main()
              {
                  int a, b[10];
                  cin >> a;
                  for (int i = 0; i < a; i++)
                  {
                      cin >> b[i];
                  }
                  for (int i = 1; i < a; i++)
                  {
                      cout << b[i] << " ";
                  }
                  cout << b[0];
                  return 0;
              }
              
              • 1
                @ 2023-11-22 19:40:31
                #include <bits/stdc++.h>//万能开头
                using namespace std;
                int main()
                {
                	int n, i, x;//定义变量
                	cin >> n;
                	int a[n];
                	for (i = 0; i < n; i++)
                    {
                		cin >> a[i];
                	}
                	cin >> x;
                	for (i = x; i <= n - 1; i++)
                    {
                		int t = a[i - 1];
                		a[i - 1] = a[i];
                		a[i] = t;
                	}
                	for (i = 0; i < n; i++)
                    {
                		cout << a[i] << " ";
                	}
                	return 0;//结束
                }
                
                • 1
                  @ 2023-8-27 21:05:08

                  #include <iostream> using namespace std; int main() { int n, a[11], x; cin >> n; for (int i=0;i<n;i++) { cin>>a[i]; } cin>>x; for (int i=0;i<x-1;i++) { cout<<a[i]<<" "; } for (int i=x;i<n;i++) { cout<<a[i]<<" "; } cout<<x; return 0; } 差不多就是这样了 求个赞image

                  • @ 2024-2-1 18:30:20

                    我帮你刷了一下颜色,但是代码没改

                    #include <iostream> using namespace std; int main() 
                    { 
                        int n, a[11], x;
                        cin >> n;   
                        for (int i=0;i<n;i++)    
                        {          
                            cin>>a[i]; 
                        } 
                        cin>>x; 
                        for (int i=0;i<x-1;i++) 
                        { 
                              cout<<a[i]<<" "; 
                        }
                        for (int i=x;i<n;i++)                                                         
                        {
                             cout<<a[i]<<" ";
                        }
                        cout<<x; 
                        return 0; 
                    }
                    
                  • @ 2024-2-1 18:34:20

                    应该是这样的

                    #include <iostream> 
                    using namespace std; 
                    int main()
                    {
                        int n, a[11], x;
                        cin >> n;
                        for (int i=0;i<n;i++)
                        {
                            cin>>a[i];
                        }
                        cin>>x;
                        for (int i=0;i<x-1;i++)
                        {
                            cout<<a[i]<<" ";
                        }
                        for (int i=x;i<n;i++)
                        {
                            cout<<a[i]<<" ";
                        }
                        cout<<x;
                        return 0;
                    }
                    
                  • @ 2024-2-1 18:35:19

                    咋又搞错了 应该是这样的

                    #include <iostream> 
                    using namespace std; 
                    int main()
                    {
                        int n, a[11], x;
                        cin >> n;
                        for (int i=0;i<n;i++)
                        {
                            cin>>a[i];
                        }
                        cin>>x;
                        for (int i=0;i<x-1;i++)
                        {
                            cout<<a[i]<<" ";
                        }
                        for (int i=x;i<n;i++)
                        {
                            cout<<a[i]<<" ";
                        }
                        cout<<x;
                        return 0;
                    }
                    
                • 1
                  @ 2023-8-12 12:53:04

                  我想知道,为什么会有这么多LV10的大佬来一星题单凑热闹? ⑥

                • 0
                  @ 2024-6-10 12:43:04

                  swap做法


                  #include <bits/stdc++.h> 
                  using namespace std;
                  int n,a[15];
                  int main()
                  {
                      cin >> n;
                      for (int i = 1;i <= n;i++)
                      {
                          cin >> a[i];
                      }
                      for (int i = 1;i < n;i++)
                      {
                          swap(a[i],a[i+1]); //交换a[i]和a[i+1]项
                      }
                      for (int i = 1;i <= n;i++)
                      {
                          cout << a[i] << " "; //输出
                      }
                      return 0;
                  }
                  
                  
                • 0
                  @ 2024-6-10 11:17:34
                  # AC!!!!!!!!!!!!!!!!!!!!!!!!!!!
                  #include <bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                      int n,a[11],x;
                      cin>>n;
                      for (int i=0;i<n;i++)   cin>>a[i];
                      cin>>x;
                      for (int i=0;i<n;i++){
                          if (i==x-1){
                              continue;
                          }//只要改变输出顺序即可!!!!!!!!
                          cout<<a[i]<<" ";
                      }
                      cout<<a[x-1];
                      return 0;
                  }
                  ```
                  
                • 0
                  @ 2024-6-10 10:15:07

                  一個比較多循環的作法,看看就好:-)

                  #include<bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                      int n,a[11],x;//定義
                      cin>>n;
                      for(int i=0;i<n;i++)
                      {
                          cin>>a[i];
                      }
                      cin>>x;
                      for(int j=0;j<x-1;j++)輸出a[x-1]前的數
                      {
                          cout<<a[j]<<" ";
                      }
                      for(int k=x;k<n;k++)//輸出a[x-1]後的數
                      {
                          cout<<a[k]<<" ";
                      }
                      cout<<a[x-1];//輸出a[x-1],結束
                  return 0;
                  }
                  
                  • 0
                    @ 2024-3-25 23:18:59

                    投机取巧的方法

                    #include<bits/stdc++.h>
                    using namespace std;
                    int main(){
                        int n,x;cin>>n;
                        int a[n+2];
                        for(int i=1;i<=n;i++){
                            cin>>a[i];
                        }
                        a[n+1]=a[1];//把第一位放到最后一位
                        for(int i=2;i<=n+1;i++){
                            cout<<a[i]<<' ';
                        }
                        return 0;
                    }
                    
                    • 0
                      @ 2024-2-1 21:17:32

                      image


                      直接上代码👇

                      using namespace std;
                      int n,a[35],x; 
                      int main()
                      {
                      	cin>>n;
                      	for(int i=1;i<=n;i++)
                      	{
                      		cin>>a[i];
                      	}
                      	cin>>x;
                      	for(int i=1;i<=n;i++)
                      	{
                      		if(a[i]==x)//先不输出a[x] 
                      		{
                      			continue; 
                      		}
                      		cout<<a[i]<<" "; //别忘了空格 
                      	}
                      	cout<<a[x];//最后输出a[x] 
                      	return 0;
                      }
                      //自创代码,求赞!!!!!!!
                      

                      image

                      AC,请放心Copy (先点赞!image

                      • 0
                        @ 2024-2-1 18:44:20

                        这一道题思维可以转个弯,可以先把不是x的值输出,最后再输出x,注意!要加空格!上代码~ 全网最短AC代码如下↓共12行


                        #include<iostream>
                        using namespace std;
                        int main(){
                            int b,c,a[10];
                            cin>>b;
                            for(int d=0;d<b;d++)cin>>a[d];
                            cin>>c;
                            for(int d=0;d<b;d++)
                            if(a[d]!=c)cout<<a[d]<<" ";
                            cout<<c;
                            return 0;
                        }
                        

                        • 0
                          @ 2024-1-7 13:50:05
                          #include <bits/stdc++.h>
                          using namespace std;
                          int main()
                          {
                              int n,x,a[10];
                              cin>>n;
                              for(int i=1;i<=n;i++)
                              {
                                  cin>>a[i];
                              }
                              cin>>x;
                              for(int i=1;i<=n;i++)
                              {
                                  if(a[i]!=x)
                                  {
                                      cout<<a[i]<<" ";
                                  }
                              }
                              cout<<x;
                              return 0;
                          }
                          
                          

                          信息

                          ID
                          159
                          时间
                          1000ms
                          内存
                          16MiB
                          难度
                          4
                          标签
                          递交数
                          6049
                          已通过
                          2644
                          上传者