I tried running a program on Sublime Text 3 with a custom build. I think I have entered into an infinite loop.
I have read a few other answers about Sublime Text 3 entering into infinite loop. But none of them answer my question.
The program is in c++
. I am inputting text from a file called input.in
and outputting to output.out
. There isn't something in the code that can turn into a potential infinite loop.
I could solve the problem by deleting output.out
and then making another file by the same name. But I don't think that this is the only way and neither the best way. Does anyone have a better method.
I tried to delete all the input from input.in
. That just made the problem worse. The program started writing lots of 0000 0000
blocks to output.out
. After thousands of such lines it starts printing alphanumeric strings of length 4 (which might also be hexadecimal numbers not quite sure)
I have already tried killing sublime text from terminal. But when I reopen it the file output.out
is still filling.
I also tried Cancel Build
. Even that doesn't help.
My code is
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>
#define ll long long
#define rep(a,b) for(int i = a; i<b; i++)
#define debug(s) cout<<s
using namespace std;
float err = 1e-7;
int main(){
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.in", "r", stdin);
// for writing output to output.txt
freopen("output.out", "w", stdout);
#endif
int a;
while(scanf("%d",&a) == 1){
int ans = 0;
vector<int> v1;
std::vector<int> v2;
for(int i = a+1;i<=2*a;i++){
for(int j = i; j<100000000000; j++){
//printf("checking for i = %d and j = %d\n", i,j);
if(abs(1.0/a-1.0/j - 1.0/i)<err){
//arr.push_back("1/%d = 1/%d + 1/%d\n"+a+j+i) ;
v1.push_back(j);
v2.push_back(i);
ans++;
break;
}
if(1.0/j + 1.0/i < 1.0/a){
break;
}
}
}
printf("%d\n", ans);
for(int i = 0; i<ans; i++){
printf("1/%d = 1/%d + 1/%d\n",a,v1.at(i),v2.at(i));
}
}
}
Any help would be appreciated.
EDIT: I am not taking input from the terminal or the small box that appears in Sublime text. I am taking input from a file and that is what makes the problem different from the suggested duplicate. The other methods like cancelling build don't help which would help the question asker in the sugested duplicate