Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Created January 2, 2012 19:17
Show Gist options
  • Save hhc0null/1551765 to your computer and use it in GitHub Desktop.
Save hhc0null/1551765 to your computer and use it in GitHub Desktop.
aoj-0004-Simultaneous_Equation.cpp
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
// "dbg" means "debug"
/*
void fdbg(int *dbg) {
int i;
for(i = 0; i < 6; i++) {
cout << dbg[i] << " " << flush;
}
cout << endl;
}
*/
void ve_calc(double* ary, double* ans) {
int i, j, tmp;
for(i = 0; i < 4; i += 3) {
if(ary[i] < 0) {
for(j = 0; j < 3; j++) {
ary[i + j] *= -1; // minus -> plus
}
}
}
//fdbg(ary);
// dbg: ok
if(ary[0] > ary[3]) {
for(i = 0; i < 3; i++) {
// replacing(?)
tmp = ary[0 + i];
ary[0 + i] = ary[3 + i];
ary[3 + i] = tmp;
}
}
//fdbg(ary);
// dbg: ok
while(ary[3] - ary[0] >= 0) {
for(i = 0; i < 3; i++) {
// calc
ary[3 + i] -= ary[0 + i];
}
}
//fdbg(ary);
// dbg: ok
for(i = 0; (i + 1) < 5; i += 3) {
if(ary[i + 1] < 0) {
for(j = 0; j < 2; j++) {
// minus -> plus
ary[(i + 1) + j] *= -1;
}
}
}
//fdbg(ary);
// dbg:
for(i = 0; 2 - i > 0; i++) {
// nemui
// osasshi kudasai!
ary[5 - i] /= ary[4];
}
//fdbg(ary);
// dbg: ok
while(ary[1] - ary[4] >= 0) {
for(i = 0; i < 2; i++) {
// nemui
ary[1 + i] -= ary[4 + i];
}
}
//fdbg(ary);
// dbg: ok
for(i = 0; i < 4; i += 3) {
// "ah...nn...///"
*ans = ary[2 + i];
ans++;
}
// 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;
}
@hhc0null
Copy link
Author

hhc0null commented Jan 2, 2012

This is the WRONG answer of AOJ-0004.
Please give me any advices!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment