解题思路:
萌新尝试了下用数组实现左右链表
注意事项:
参考代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cstring>
using namespace std;
const int maxn = 1010;
int a[maxn],score[maxn],b[maxn];
int lefts[maxn],rights[maxn]; //链
void lnk(int l,int r){
lefts[r] = l;
rights[l] = r;
}
int main()
{
int an,bn;
cin >> an >> bn;
for(int i = 1; i <= an; i++){
cin >> a[i] >> score[i];
rights[i] = i+1;
lefts[i] = i-1;
}
rights[0] = 1; lefts[0] = an;
int tmp;
for(int i = 1; i <= bn; i++){
cin >> b[i] >> tmp;
}
for(int i = 1; i <= bn; i++){
for(int j = rights[0]; rights[j] != 0; j = rights[j]){
if(a[j] == b[i]){
int ll = lefts[j];
int rr = rights[j];
lnk(ll,rr);
an--;
break;
}
}
}
cout << an << endl;
for(int j = rights[0]; rights[j] != 0; j = rights[j]){
cout << a[j] << " " << score[j] << endl;
}
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:584 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:588 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:642 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:1482 |
The 3n + 1 problem (C语言代码)浏览:603 |
DNA (C语言代码)浏览:564 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:541 |
1012题解浏览:938 |
杨辉三角 (C语言代码)浏览:734 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:683 |