Skip to content

Instantly share code, notes, and snippets.

@jlfwong
Created March 1, 2010 21:57
Show Gist options
  • Save jlfwong/318859 to your computer and use it in GitHub Desktop.
Save jlfwong/318859 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <set>
#include <utility>
using namespace std;
int main() {
FILE* fin = fopen("freq.txt","r");
set<double> freqs;
double n;
while(fscanf(fin,"%lf",&n) != EOF) {
freqs.insert(n);
}
printf("Done insertion\n");
double x,y,z;
printf("X: ");
cin >> x;
printf("Y: ");
cin >> y;
printf("Z: ");
cin >> z;
int CAP = 300;
for (int a = -CAP; a <= CAP; a++) {
for (int b = -CAP; b <= CAP; b++) {
for (int c = -CAP; c <= CAP; c++) {
double curFreq = (double)(((int)((a*x + b*y + c*z) * 10 + 0.5))/10.0);
if (freqs.count(curFreq)) {
freqs.erase(curFreq);
printf("%d(%.2lf) + %d(%.2lf) + %d(%.2lf) = %.2lf\n",a,x,b,y,c,z,curFreq);
}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment