#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int M, N, num[30000];
scanf("%d%d", &M, &N);
for (int i = 0; i < M; i++) {
scanf("%d", &num[i]);
}
vector<int> box;
int done = 0, need = 0;
while (N--) {
int index;
scanf("%d", &index);
while (box.size() < index) {
vector<int>::iterator it = lower_bound(box.begin(), box.end(), num[done]);
box.insert(it, num[done++]);
}
printf("%d\n", box[need++]);
}
if (T) {
puts("");
}
}
return 0;
}
#include <cstdio>
#include <vector>
#include <algorithm>
usingnamespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int M, N, num[30000];
scanf("%d%d", &M, &N);
for (int i = 0; i < M; i++) {
scanf("%d", &num[i]);
}
vector<int> box;
int done = 0, need = 0;
while (N--) {
int index;
scanf("%d", &index);
while (box.size() < index) {
vector<int>::iterator it = lower_bound(box.begin(), box.end(), num[done]);
box.insert(it, num[done++]);
}
printf("%d\n", box[need++]);
}
if (T) {
puts("");
}
}
return 0;
#include <cstdio>
#include <vector> // c++
#include <algorithm> // never used
usingnamespace std; // c++
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int M, N, num[30000];
scanf("%d%d", &M, &N);
for (int i = 0; i < M; i++)
{
scanf("%d", &num[i]);
}
vector<int> box; // C++
int done = 0, need = 0;
while (N--)
{
int index;
scanf("%d", &index);
while (box.size() < index) // C++
{
vector<int>::iterator it = lower_bound(box.begin(), box.end(), num[done]); // C++
box.insert(it, num[done++]); // C++
}
printf("%d\n", box[need++]);
}
if (T)
{
puts("");
}
}
return 0;
}
Here you go, box is the only element that's not portable to C so all lines containing box have to be replaced somehow ;)
or you can implement vector<int> and vector<int>::iterator with structs and without templates in C :b
Both of you still have vectors and iterators in the code he needed in the language C. Im wondering, are vectors and iterators part of C. Werent they introduced in c++?
i mean "Standard output is empty" from ideone.com
how to adjust the code so that I can enter the input rather than create a file??
sorry i am a beginner,i need a template
Of course it would be empty as you explicitely redirected everything going to the standard output to a file. And ideone cannot work with files. Actually I ever seen only two online compilers which can read from files and only one which can write to some explicitely allowed files.
Do not use online compilers if you need more than basic proof-of-concept things.
thanks I know how to use input/out file now~
but I do not know how to change the following C++ code to C ...can anyone help me?thanks
this is the code from the question of poj1760~but i dont know how to changing to C program http://poj.org/problem?id=1760
And I will repeat again: you need several thousands lines of code to port map to C.
Additionally this code is terrible and suboptimal. It should be forgotten, not studied and ported.
@sirrunrun, you will need very good linked list understanding, to solve last problem in C.
besides linked lists, another idea comes to mind is c-string sorting(lexicographic, in between backspaces "\" ). but it can get very complicated too. because you have to sort according to various inner layers.