8 solutions
-
1
-
0
#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
#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
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
用指针做的,仅供参考
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; }
- 1
Information
- ID
- 227
- Time
- 1000ms
- Memory
- 64MiB
- Difficulty
- 6
- Tags
- # Submissions
- 83
- Accepted
- 28
- Uploaded By