8 solutions

  • 1
    @ 2024-12-20 21:14:21

    超短代码

    数组方法

    #include <bits/stdc++.h>
    using namespace std;
    int ppp[12];
    int main(){
    	int n,ii,y;
    	cin>>n;
    	for(int i=0;i<n;i++)cin>>ppp[i];
    	cin>>ii>>y;
    	for(int i=0;i<ii-1;i++)cout<<ppp[i]<<" ";
    	cout<<y<<" ";
    	for(int i=ii-1;i<n;i++)cout<<ppp[i]<<" ";
    	return 0;
    }
    
    • 1
      @ 2023-10-4 11:17:05
      using namespace std; 
      int main() { 
      int n,m,x; 
      cin>>n; 
      int a[n+1]; 
      for(int i=1;i<=n;i++) { 
      cin>>a[i]; 
      } 
      cin>>m; 
      cin>>x; 
      int b[n+2]; 
      for(int i=1;i<m;i++) { 
      b[i]=a[i]; 
      } 
      b[m]=x; 
      for(int i=m+1;i<=n+1;i++) { 
      b[i]=a[i-1]; 
      } 
      for(int i=1;i<=n+1;i++) { 
      cout<<b[i]<<" "; 
      } 
      }`
      
      
      
      • 0
        @ 2024-11-29 21:17:37
        #include <bits/stdc++.h>
        using namespace std;
        
        struct fuck
        {
        	int data;
        	fuck* next;
        };
        
        int n, x, y, t;
        
        int main()
        {
        	fuck* fhead = new fuck; // 假头
        	fuck* head; // 真头
        	head = fhead;
        	cin >> n;
        	for (int i = 1; i <= n; i++)
        	{
        		fhead -> next = new fuck;
        		fhead = fhead -> next;
        		cin >> t;
        		fhead -> data = t;
        		fhead -> next = NULL;
        	}
        	cin >> x >> y;
        	fhead = head;
        	for (int i = 1; i < x; i++)
        		fhead = fhead -> next;
        	fuck* xin = new fuck;
        	xin -> next = fhead -> next;
        	xin -> data = y;
        	fhead -> next = xin;
        	head = head -> next;
        	while (head != NULL)
        	{
        		cout << head -> data << " ";
        		head = head -> next;
        	}
        	
        	return 0;
        }
        
        • 0
          @ 2024-10-15 19:25:56
          #include<bits/stdc++.h>
          
          using namespace std;
          string n[100010];
          int main(){
            //世上最另类的做法(字符串),仅供欣赏
          	int s;
          	cin>>s;
          	for(int i=1;i<=s;i++){
          		cin>>n[i];
          	}
          	int k;
          	int l;
          	cin>>k;
          	cin>>l;
          	for(int i=1;i<=k-1;i++){
          		cout<<n[i]<<" ";
          	}
          	cout<<l<<" ";
          	for(int i=k;i<=s;i++){
          		cout<<n[i]<<" ";
          	}
          	return 0;
          }
          
          
          • 0
            @ 2023-10-18 16:34:53

            oik,前面那道题改改就行了😄

            #include <bits/stdc++.h>
            using namespace std;
            struct Node{
            	int data;
            	Node *next;
            };
            Node *head,*p,*r,*s;
            int idx = 0;
            int main(int argc, char **argv){
            	int n,x,a,y;
            	head = new Node;
            	r = head;
            	cin >> n;
            	for (int i = 0;i < n;i++){
            		cin >> a;
            		p = new Node;
            		p -> data = a;
            		p -> next = NULL;
            		r -> next = p;
            		r = p;
            	}
            	p = head -> next;
            	cin >> x >> y;
            	if(x == 1){
            		s = new Node;
            		s -> data = y;
            		s -> next = head -> next;
            		head -> next = s;
            		p = head -> next;
            		while (p -> next != NULL){
            			cout << p -> data << ' ';
            			p = p -> next;
            		}
            		cout << p -> data;
            		return 0;
            	}
            	while (idx < x - 2){
            		p = p -> next;
            		idx++;
            	}
            	s = new Node;
            	s -> data = y;
            	s -> next = p -> next;
            	p -> next = s;
            	p = head -> next;
            	while (p -> next != NULL){
            		cout << p -> data << ' ';
            		p = p -> next;
            	}
            	cout << p -> data;
            	return 0;
            }
            
            • 0
              @ 2023-10-13 20:13:24

              用指针做的,仅供参考

              using namespace std;
              struct note{
              	note* nest;
              	int num;
              };
              note arr[110];
              int main(){
              	int n,tamp,x,y;
              	cin>>n;
              	for(int i=1;i<=n;i++){
              		cin>>tamp;
              		arr[i].num=tamp;
              		arr[i-1].nest=&arr[i];
              	}
              	cin>>x>>y;
              	arr[n-1].nest=&arr[n];
              	bool bbb=0;
              	for(int i=0;i<=n-1;i++){
              		if(i==x-1 && bbb==0){
              			cout<<y<<' ';
              			i--;
              			bbb=1;
              		}
              		else cout<<arr[i].nest->num<<' ';
              	}
              	
              	return 0;
              }
              
              • @ 2023-11-4 16:10:59

                你这个指针 *nest 用了等于没用哦 image

            • -1
              @ 2023-10-5 11:22:36

              #include using namespace std; int main(){ int n,x,m; cin>>n; int a[n+1]; for( int i=1;i<=n;++i) cin>>a[i] ; cin>>x; cin>>m;

              for(int i=n;i>=x;i--){ a[i+1]=a[i]; } a[x]=m; for( int i=1;i<=n+1;++i) cout<<a[i]<<" "; }

              • -2
                @ 2023-10-3 11:08:53

                #include using namespace std; int main() { int n,m,x; cin>>n; int a[n+1]; for(int i=1;i<=n;i++) { cin>>a[i]; } cin>>m; cin>>x; int b[n+2]; for(int i=1;i<m;i++) { b[i]=a[i]; } b[m]=x; for(int i=m+1;i<=n+1;i++) { b[i]=a[i-1]; } for(int i=1;i<=n+1;i++) { cout<<b[i]<<" "; } }

                • 1

                Information

                ID
                227
                Time
                1000ms
                Memory
                64MiB
                Difficulty
                6
                Tags
                # Submissions
                83
                Accepted
                28
                Uploaded By