All pastes #791151 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-11-20 19:34 UTC
rendered paste body
#include <iostream>
#include <vector>
#include <cmath> // for pow function

using namespace std;

typedef vector <double> Dvector;
typedef vector <Dvector> Dmatrix;

Dmatrix GetA(){
		Dmatrix grid;
		int number(0);
		string matrixa;
		string matrixacopy("");
		cout<< "Numbers in matrix A: ";
		getline(cin,matrixa);
		matrixa+=" ";
		matrixacopy+=matrixa;
		while (matrixacopy.find(" ") != -1)
		{
			number+=1;
			matrixacopy.erase(0,(matrixacopy.find(" "))+1);
		}
		for (int r=0; r<sqrt(number); r++){
			vector <double> dummy;
			grid.push_back(dummy);
			for(int c=0;c<sqrt(number);c++){
				string numb("");
				numb += matrixa.substr(0,matrixa.find(" "));
				double num = atoi(numb.c_str());
				grid[r].push_back(num);
				matrixa.erase(0,(matrixa.find(" "))+1);
			}
		}
			for (int r=0;r<sqrt(number);r++){
				for (int c=0;c<sqrt(number);c++){
					cout<<grid[r][c]<<" ";
				}
				cout<<endl;
		}
}

int main(){

Dmatrix A;     
Dvector b,x;

A=GetA();
return(0);
}