Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Created January 3, 2012 10:41
Show Gist options
  • Save hhc0null/1554423 to your computer and use it in GitHub Desktop.
Save hhc0null/1554423 to your computer and use it in GitHub Desktop.
aoj-0004-Simultaneous_Equation-1.cpp
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
void ve_calc(double* ary, double* ans) {
int i, j, tmp;
for(i = 0; i < 2; i++) {
*(ans + i) = (ary[2 - 2 * i] * ary[4 + i] - ary[1 + i] * ary[5 - 2 * i]) / (ary[0] * ary[4] - ary[1] * ary[3]) + 0;
}
// dbg: ok
}
int main() {
int i, j;
double tmp;
double *ary = new double[6];
vector<double> vect;
i = j = 0;
/* input */
for(i = 0; cin >> tmp; i++){
vect.push_back(tmp);
}
// dbg: ok
tmp = i / 6;
// dbg: ok
double *ans = new double[(int)tmp * 2];
// ok
/* substitue vect for array */
for(i = 0; i < tmp; i++) {
for(j = 0; j < 6; j++) {
ary[j] = vect.at(i * 6 + j);
}
// ok
/* call the "ve_calc()" */
ve_calc(ary, ans + i * 2);
}
// dbg: ok
for(i = 0; i < tmp * 2; i += 2) {
cout << setprecision(4) << showpoint << ans[i] << " " << ans[i + 1] << endl;
}
///////////////////////////////////////////////////////
// Oh... My coding skil is too low...?
// I must learn more hard!
// ...Are there sentences is sure??
// <<MO DO NI DE MO NA RE!!>>
///////////////////////////////////////////////////////
delete[] ary;
delete[] ans;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment