0
Good morning. I would like a help to create a code that is accepted by SPOJ.
The proposed problem is the following: "You get an ordered sequence of n integers S = S1, s2, ..., Sn and an ordered sequence of integers m Q = Q1, Q2, ..., qm. Please print in ascending order all those that do not belong to Q."
I’m trying to do it in C++ and using vectors. But I’m running into an infinite loop that I can’t handle.
And I still haven’t thought about how to compare the vectors and display those that are only present in sequence S.
Follow the code I’ve made so far:
#include <iostream>
using namespace std;
int main () {
int S, Q;
cin >> S;
int * S_vetor = new int[S];
for (int i = 0; i < S; i++) {
cin >> S_vetor[i];
}
cin >> Q;
int * Q_vetor = new int[Q];
for (int i = 0; i <= Q; i++) {
cin >> Q_vetor[i];
}
return 0;
}
From now on, I am grateful for the attention.
what values you are entering for S and Q, when the program runs?
– Leonardo Alves Machado
I suggest putting text messages before
cin
- I think that’s your "infinite loop"...– Leonardo Alves Machado
Values between -100 and 100. As well, text messages before Cin?
– marciliojrr
Ah, at Codeblocks he’s got the fever...
– marciliojrr
the
cin
blocks execution. If you have not typed all expected values, it seems that the program has locked... Puts acout >> "digite o valor de..."
, for example...– Leonardo Alves Machado
But the SPOJ requires that the answer be only to appear equal to their example: Appear the size of the vector, below its elements. Then the size of the other vector, under its elements. Finally, only the integers that are in the first vector and not in the second.
– marciliojrr