Note that there are some explanatory texts on larger screens.

plurals
  1. POC++, Reading and Saving large amount of numbers
    primarykey
    data
    text
    <p>I have to solve a problem and i need your help, so thanks in advance. As you can see, title says almost everything. There is a file "domes.in" (which is a textfile), which contains 10.000.000 pairs of integers From (1 - 100.000), so in the first part, I have to save all those numbers, in less than 1 sec.</p> <p>First, I have tried creating an int array of 20.000.000 places, so that i could save the numbers one by one The size of the array is so big that the program does not respond.</p> <p>Before you read the code, read the task, but please just answer my question and do not post any code, because it is a problem of an online competition and i would like to write it by myself.</p> <pre><code>#include &lt;fstream&gt; using namespace std; int main() { int n, m, a, b; //N(Value) M(Pairs) int t = 0; int r = 0; int j; ifstream infile("domes.in"); infile &gt;&gt; n &gt;&gt; m; //N = 100.000 M = 10.000.000 int domes[m*2]; for (j=0; j&lt;m; j++) //For 1 to 10.000.000 { infile &gt;&gt; a &gt;&gt; b; //Save 10.000.000 Integers domes[t++] = a; domes[t++] = b; } for (j=1; j&lt;=n; j++) //For J = 1 - 100.000 { int i=0; for (int k=0; k&lt;t; k++) //If the point J is appeared if (domes[k] == j) //+1 Link i++; if (i == 1) //If Links &lt; 2 (of number J) r++; //+1 Point is connected with less than 2 points } //Else move on to ++J infile.close(); ofstream outfile("domes.out"); outfile &lt;&lt; r; return 0; } </code></pre> <p>Now it seems that it might work, but again the program doesn't respond (In runtime, in raises an error, which says that the program stopped running. There are any other build errors or mistakes in the code). </p> <p>What am i doing wrong?</p> <p>The TextFile: 100000 10000000</p> <p>2344 3444 </p> <p>3345 4564 </p> <p>5566 9455 //Random integers up to 100.000</p> <p>//..........</p> <p>//Edit: I Removed the struct "DOMES" from the code, since it was the same thing</p> <p>The Task: I will explain it with my own words, because it is complicated. The are 100.000 points on the map. These points, are connected (There are 10.000.000 links). I have to find the points which have only a single connection (Each Point has at least 1 connection). </p> <p>For example:</p> <p>5 4 (N = 5, M = 4) N(Max Value) M(Pairs)</p> <p>1 2</p> <p>2 3</p> <p>4 5</p> <p>3 4</p> <p>There are 2 points that have a single connection: 1 and 5 (1 is connected with 2) and (5 is connected with 4). The rest of the points are connected at least twice:</p> <p>2: 1-2, 2-3 </p> <p>3: 2-3, 3-4 </p> <p>4: 4-3, 4-5</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload