📄 030300423integer.cpp
字号:
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
class Node{
friend class LinkedSet;
private:
int element;
Node *next;
};
class LinkedSet
{
public:
LinkedSet(){first=0;}
~LinkedSet();
LinkedSet& Insert(int &x);
void Output(int i);
private:
Node *first;
};
LinkedSet::~LinkedSet()
{
Node *next;
while(first)
{
next=first->next;
delete first;
first=next;
}
}
LinkedSet& LinkedSet::Insert(int &x)
{
Node *p=first;
Node *q=p;
while(p&&p->element<=x)
{
q=p;
p=p->next;
}
Node *y=new Node;
y->element=x;
y->next=p;
if(p==q) first=y;
else q->next=y;
return *this;
}
void LinkedSet::Output(int i)
{
Node *current;int j=1;
for(current=first;current;current=current->next)
{
if(j==i){ out<<current->element<<" ";break;}
j++;
}
}
int main()
{
if(in.fail())
{
cout<<"input.txt is not exist!";
exit(1);
}
int m,n;
in>>m>>n;
int *a=new int [m];
int *b=new int [n+1];
b[0]=0;
for(int j=0;j<m;j++)
in>>a[j];
for(j=1;j<=n;j++)
in>>b[j];
LinkedSet shu;
int i=1;
for(j=0;j<m&&i<=n;j++)
{
int t,s;
shu.Insert(a[j]);
if(b[i]==j+1){shu.Output(i);i++;}
while(b[i]==b[i-1])
{shu.Output(i);i++;}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -