Programming Contest Problem output giving extras blank spaces

Hi, I am doing an exercise of programming called Erdös Numbers (https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=985) and the only problem is in how the code is generating the output.

Here is an example of a correct input/output:

Input:
2
4 3
Smith, M.N., Martin, G., Erdos, P.: Newtonian forms of prime factors
Erdos, P., Reisig, W.: Stuttering in petri nets
Smith, M.N., Chen, X.: First order derivates in structured programming
Jablonski, T., Hsueh, Z.: Selfstabilizing data structures
Smith, M.N.
Hsueh, Z.
Chen, X.

Output:
Scenario 1
Smith, M.N. 1
Hsueh, Z. infinity
Chen, X. 2

Example of mine Output for the same Input:




Scenario 1
Smith, M.N. 1
Hsueh, Z. infinity
Chen, X. 2

Notice that are 4 blank spaces coming out before the answer is given. Can someone help me figure out what is making this happen (I believe that this is happening because of something related to the getline parts of the code)?
If someone that is willing to help and could not understand the code, post a comment and i will try to explain.
Thanks!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
vector<string> split(string str,char delimiter){
	vector<string> internal;
	stringstream ss(str);
	string tok;
	while(getline(ss,tok,delimiter)){
		internal.push_back(tok);
	}
	return internal;
}
int main(){
	string cases,papers,names;
	int p,n,c,cont=1;
	getline(cin, cases);
	c=atoi(cases.c_str());
	while(c--){
		getline(cin,papers,' ');
		getline(cin,names);
		p=atoi(papers.c_str());
		n=atoi(names.c_str());
		map<string, pair<bool,int> > mapName;
		mapName["Erdos, P."]=make_pair(0,0);
		for(int i=0;i<p;i++){
			vector<string> temp,comp;
			int menor=-1;
			bool entrou=0;
			string aux,lixo,nome,nomeMenor;
			getline(cin, aux, ':');
			getline(cin,lixo);
			temp = split(aux,',');
			for(int j=0;j<temp.size();j=j+2){
				nome=(temp[j]+','+temp[j+1]);
				if(j==0)
				    nome.erase(remove(nome.begin(), nome.end(), '\n'), nome.end());
				if(nome[0]==' ')
		    		nome.erase(nome.begin());
				if(mapName.find(nome) == mapName.end()){
                    mapName[nome] = make_pair(0,-1);
				}
                comp.push_back(nome);
			}
			for(int j=0;j<comp.size();j++){
				if(mapName[comp[j]].second!=-1){
					if(entrou){
						if(menor>mapName[comp[j]].second){
                            menor=mapName[comp[j]].second;
						    nomeMenor=comp[j];
    					}
					}
					else{
						entrou=1;
						menor=mapName[comp[j]].second;
						nomeMenor=comp[j];
					}
				}
			}
			for(int j=0;j<comp.size();j++){
				if(entrou){
                    if(comp[j]!=nomeMenor){
                        mapName[comp[j]].second=menor+1;
                        cout<<endl;
					}
				}
			}
		}
		string nomeParaMostrar[n];
		for(int i=0;i<n;i++){
			getline(cin, nomeParaMostrar[i]);
			mapName[nomeParaMostrar[i]].first=1;
		}
		map<string, pair<bool,int> >::iterator it;
		cout<<"Scenario "<<cont<<endl;
		for(int i=0;i<n;i++){
			if(mapName[nomeParaMostrar[i]].second!=-1)
				cout<<nomeParaMostrar[i]<<" "<<mapName[nomeParaMostrar[i]].second<<endl;
			else
			    cout<<nomeParaMostrar[i]<<" infinity"<<endl;
		}
		cont++;
		if(c>1)
			cout<<endl;
	}
	return 0;
}
The program doesn't compile on my machine because you are trying to use a Variable Length Array in line 72 which the C++ standard doesn't allow. You know about std::vector why don't you use a vector instead?

Next what is the purpose of lines 86 and 87?

Oh, sure, I will use an vector, thanks for the advice.
The purpose is to not do an extra blank line at the last case (between cases must have a blank line).
Still couldn't fix the problem in output. :/
The problem is probably being caused because the example you're using has two Scenarios but you only have the data for one.

Topic archived. No new replies allowed.