Esempio n. 1
0
void RoomCost::setCustom(ifstream& file)
{
    int periodBegin;    // Period start
    int periodEnd;        // Period end
    int count;            // Count of entries under start - end (count)
    float cost;            // Cost for one entry
    string roomType;    // Type of room
    string costType;    // Cost

    CostInterval* interval;

    file >> periodBegin;
    file >> periodEnd;
    file >> count;
    file.ignore();

    for (int i = 0; i < count; i++)    // Go over all entries
    {
        getline(file, roomType, ' ');
        getline(file, costType, ' ');
        file >> cost;
        file.ignore();
                            // Thanks Ubama for not adding switch for string
        if (costType == "uke")    // If is week cost
            interval = new WeekCost(periodBegin, periodEnd, cost);
        else if (costType == "helg")    // if weekend cost
            interval = new WeekendCost(periodBegin, periodEnd, cost);
        else   // or everything else
            interval = new CostInterval(periodBegin, periodEnd, cost);

        customCosts[getType(roomType)]->add((Element*)interval);
    }
}
Esempio n. 2
0
  static void readGrammar(ifstream& infile, map<string, Definition>& grammar)
  {   
    // Keep parsing until EOF is reached.
    while(infile.good())
    { 
      // Ignore all chars until '{' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '{');

      // Ignore all chars until '\n' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '<');

      if(infile.good()) 
      {
        // Beginning of a definition; parse into program.
        Definition myDefinition = Definition(infile);
        
        // Fill map.
        string myNonTerminal = myDefinition.getNonterminal();
        pair<string, Definition> myPair(myNonTerminal, myDefinition);
        grammar.insert(myPair);
      }
    }

    infile.close();
}
Esempio n. 3
0
void ReadOneTrainingSample(ifstream& is,FDImage& image)
{
	int i,j;
	char buf[256];

	FDImage timage;
	ASSERT(sx<=256 && sy<=256);
	is>>image.label; is.ignore(256,'\n');
	ASSERT( (image.label == 0) || (image.label == 1) );

	is>>timage.height>>timage.width; is.ignore(256,'\n');
	ASSERT(timage.height==sx); 
	ASSERT(timage.width==sy);

	timage.SetSize(CSize(timage.height,timage.width));

	for(i=0;i<timage.height;i++)
	{
		is.read(buf,timage.width);
		for(j=0;j<timage.width;j++) 
		{
			timage.data[i][j] = REAL(int(unsigned char(buf[j-1])));
			ASSERT(timage.data[i][j]>=0 && timage.data[i][j] <= 255);
		}
	}
	is.ignore(256,'\n');
	timage.Resize(image,40.0/24.0);
	timage.Clear();
}
Esempio n. 4
0
// handles all file inputs
void Room::input(ifstream& in1) {
	in1.getline(name,50);
	in1.ignore(1);
	in1.getline(description,300);
	in1 >> exit[0] >> exit[1] >> exit[2] >> exit[3];
	in1.ignore(1);
}
Esempio n. 5
0
void ReadOneTrainingSample(ifstream& is,IntImage& image)
{
	int i,j;
	char buf[256];

	ASSERT(sx<=256 && sy<=256);
	is>>image.label; is.ignore(256,'\n');
	ASSERT( (image.label == 0) || (image.label == 1) );

	is>>image.height>>image.width; is.ignore(256,'\n');
	ASSERT(image.height==sx); 
	ASSERT(image.width==sy);

	image.SetSize(CSize(image.height+1,image.width+1));
	for(i=0;i<image.height;i++) image.data[i][0] = 0;
	for(i=0;i<image.width;i++) image.data[0][i] = 0;
	for(i=1;i<image.height;i++)
	{
		is.read(buf,image.width-1);
		for(j=1;j<image.width;j++) 
		{
			image.data[i][j] = REAL(int(unsigned char(buf[j-1])));
			ASSERT(image.data[i][j]>=0 && image.data[i][j] <= 255);
		}
	}
	is.ignore(256,'\n');
}
Esempio n. 6
0
// Reads messages file and pushes email messages to the stack
void readmessages(StackType& email, ifstream& in)
{
	Message message; // Redo the constructor

	while (!(in.eof())) {

		char Body[1000];
		char FROM[6], sender[50];
		char DATE[6], date[15];
		char SUBJECT[9], subject[60]; // Body, sender,date, and subject initialized as character arrays

		in >> FROM;
		in.ignore(1);
		in.getline(sender,50);
		in >> DATE >> date;
		in >> SUBJECT;
		in.ignore(1);
		in.getline(subject,60);
		in.ignore(100,'\n');  // reads the data from messagesfile.txt

		in.get(Body,1000,'#');

		message.setSender(sender);
		message.setDate(date);
		message.setSubject(subject);
		message.setBody(Body); // Sets the information into a message object

		email.Push(message);   // Pushes the message object onto the emails stack

		in.ignore(100,'\n');
	}
}
Esempio n. 7
0
void cTriggerList::LoadTriggersLegacy(ifstream& ifs)
{
	int temp;
	int numTriggersToLoad = 0;
	char buffer[1000];
	Free();

	if (ifs.peek() == '\n') ifs.ignore(1, '\n');
	ifs >> numTriggersToLoad;
	if (numTriggersToLoad > 10) // Myr: For some reason I can't determine my save game is suddenly
		numTriggersToLoad = 10; //      generating a value of 16842851 here. Sanity check.
	for (int i = 0; i<numTriggersToLoad; i++)
	{
		cTrigger* current = new cTrigger();

		// load the type
		if (ifs.peek() == '\n') ifs.ignore(1, '\n');
		ifs >> temp;
		current->m_Type = temp;

		// load additional data
		if (ifs.peek() == '\n') ifs.ignore(1, '\n');
		if (current->m_Type == TRIGGER_SKILL || current->m_Type == TRIGGER_STAT)
		{
			// skill/stat id
			ifs >> temp;
			current->m_Values[0] = temp;

			// what value it must reach
			ifs >> temp;
			current->m_Values[1] = temp;
		}
		else if (current->m_Type == TRIGGER_STATUS)
void AdaBoostClassifier::ReadFromFile(ifstream& f)
{
	Clear();
	f>>m_iCount; ASSERT(m_iCount>0);
	f.ignore(256,'\n');
	m_WeakClassifiers = new WeakClassifier[m_iCount]; ASSERT(m_WeakClassifiers!=NULL);
	m_rAlphas = new REAL[m_iCount]; ASSERT(m_rAlphas!=NULL);
	
	f>>m_rThreshold; f.ignore(256,'\n');
	for(int i=0;i<m_iCount;i++) f>>m_rAlphas[i]; f.ignore(256,'\n');
	for(int i=0;i<m_iCount;i++) m_WeakClassifiers[i].ReadFromFile(f); f.ignore(256,'\n');
}
Esempio n. 9
0
void ReadAndPrintFiles(ifstream& dataFileIn1, ifstream& dataFileIn2, hashT<elemType>& hashtable)
{
   char num[4];
   cout << "The hash table is shown as follow (size " << HTSize << "):" << endl;
   cout << "     indexStatusList      HashTable(0 means empty spot)" << endl;
 
   dataFileIn1 >> num;
   while (!dataFileIn1.eof())
   {
	   dataFileIn1.ignore(100, '\n');
	   hashtable.insert(hashFunction(num), atoi(num));
	   dataFileIn1 >> num;
   }
   hashtable.print();


   char num1[4];
   int hashIndex;
   bool found;
   int pCount;
   linkedQueueType<int> probeSequence;
   cout << endl << "Search for values in the hash table using values in lab8srch.dat:";
   cout << endl << " Value" << "   " << "Found?" << "   " << "# of probes" << "   " << "The probe sequence" << endl;

   dataFileIn2 >> num1;
   while (!dataFileIn2.eof())
   {
		hashIndex = hashFunction(num1);
		dataFileIn2.ignore(100, '\n');
		hashtable.search(hashIndex, atoi(num1), found, pCount, probeSequence);

		cout << setw(5) << num1;
		switch(found)
		{
		case 1: cout << setw(8) << "Yes";
			break;
		case 0: cout << setw(8) << "No";
			break;
		}
		cout << setw(11) << pCount << "         ";
	    while (!probeSequence.isEmptyQueue())
	    {
		cout << probeSequence.front() << " ";
		probeSequence.deleteQueue();
	    }
	    cout << endl;

		dataFileIn2 >> num1;
   }
}
Esempio n. 10
0
double averageGrade(double sum, char gender, ifstream& file) {

    // Instantiate helper variables
    double avg, count = 0;
    char testGender;

    // While the file is available for reading, take in the
    // gender from each line to 'testGender'. If testGender
    // matches the gender we care about, increment the counter.
    // Finally, ignore the rest of the line.
    while (file >> testGender) {
        if (testGender == gender) {
            count++;
        }
        file.ignore(50, '\n');
    }

    // Reset the readable file back to its initial state so we
    // can read it again later
    file.clear();
    file.seekg(0, ios::beg);

    // Compute and return the average
    avg = sum / count;
    return avg;

}
Esempio n. 11
0
void read_his_vcc(ifstream &in_vcc, vector <int> & i_will){ // Reading history.vcc
	int nv; in_vcc >> nv; 
	in_vcc.ignore();
		
	char c_T[3];
	long long int ts_vcc;
	double time_vcc;
	in_vcc >> c_T >> ts_vcc >> time_vcc;
	if(strcmp("T:", c_T) !=0){ 
		cout << c_T << endl;
		error(1, "(read vcc) the format is incorrect"); // check
	}
	if(ts_vcc != timestep || time_vcc != realtime) error(1, "(read vcc) the reading block might inconsistent. timestep:", 2, ts_vcc, timestep);

	vltcp.clear();
	for(int a=0; a<nv; a ++){
		int type_in, vltcp_in, ix, iy, iz;
		in_vcc >> type_in >> vltcp_in >> ix >> iy >> iz; 

		states[vltcp_in]= type_in;
		vltcp.push_back(vltcp_in); 
		iv[0]= ix;
		iv[1]= iy; 
		iv[2]= iz;

		i_will.push_back(vltcp_in);
	}
	
	if(in_vcc.eof()) error(1, "(read_vcc) unexpected eof");
}
Esempio n. 12
0
void readFile(ifstream &inf, Station stations[], int numStations, int numCars,
  Car cars[])
{
  int i, j;
  char line[256];
  inf.ignore(1000, '\n');

  for(i = 0; i < numStations; i++)
  {
    inf.getline(line, 256);
    strtok(line, ",");
    stations[i].adjCount = atoi(strtok(NULL, ","));
    
    for(j = 0; j < stations[i].adjCount; j++)
    {
      stations[i].adjacent[j] = atoi(strtok(NULL, ","));
      stations[i].distances[j] = atoi(strtok(NULL, ","));
    } // for j
  }  // for each station

  for(i = 0; i < numCars; i++)
  {
    inf.getline(line, 256);
    strtok(line, ",");
    cars[i].source = atoi(strtok(NULL, ","));
    cars[i].destination = atoi(strtok(NULL, ","));
  } // for each car 
}  // readFile()
Esempio n. 13
0
void loadArrays(ifstream &fileData, string wine[], double qsales[][4], int &row)
{
	

	for  (row = 0; row < SIZE; row++)
	{
		getline(fileData, wine[row]);

		if (fileData.eof())
		{
			break;
		}


		for (int col = 0; col < 4; col++)
		{

			fileData >> qsales[row][col];

		}

		fileData.ignore(80, '\n');

	}



}
Esempio n. 14
0
Transacao::Transacao(ifstream & in){ // le uma transacao na forma de  idcliente ; data ; lista produtos
	string data_aux;
	string lista_prod_aux;
	vector<string> produtos_aux;
	string prod_individual;

	
	//idcliente
	in >> idCliente; in.ignore(); // ignora o ;

	cout << idCliente << endl;
	//data
	getline(in, data_aux, ';');
	//cout << 77 << endl;

	data_aux.erase(data_aux.begin()); data_aux.erase(data_aux.end() - 1);               //apaga 1 e último espaço
	//cout << 33 << endl;
	Data data(data_aux);
	
	//lista de produtos
	getline(in, lista_prod_aux);
	
	istringstream instr(lista_prod_aux);
	while (getline(instr, prod_individual, ','))
	{
		prod_individual.erase(0, prod_individual.find_first_not_of(' '));           //remove espacos iniciais
		produtos_aux.push_back(prod_individual);
	}
	produtos = produtos_aux;
	

}
Esempio n. 15
0
//PULSE (<amplitude 1> <amplitude 2> <atraso> <tempo de subida> <tempo de descida> <tempo ligada> <período> <número de ciclos>)
void Tensao::carregaParamPULSE(ifstream &arq)
{
	int i = 0;
	while(arq.good() && arq.peek() != '\n')
	{
		//ignora os parenteses
		if (arq.peek() == ' ' || arq.peek() == '(' || arq.peek() == ')')
		{
			arq.ignore();
			continue;
		}
		switch(i)
		{
			case 0: 
				arq >> m_amplitude;
				break;
			case 1: 
				arq >> m_amplitude2;
				break;
			case 2: 
				arq >> m_atraso;
				break;
			case 3: 
				arq >> m_t_subida;
				break;
			case 4: 
				arq >> m_t_descida;
				break;
			case 5: 
				arq >> m_t_ligada;
				break;
			case 6: 
				arq >> m_periodo;
				break;
			case 7: 
				arq >> m_ciclos;
				break;
			default:
				arq >> m_ignora;
				break;
		}
		i++;
	}
	if(i!=8)
	{
		cout<< m_nome <<" PULSE: Numero de parametros errado" << i << "/8"<<endl;
		arq.close();
		m_erro = true;
	}

	cout<<m_nome<<" PULSE:"<<m_nome_a<<" "<<m_nome_b
		<<" "<<m_amplitude
		<<" "<<m_amplitude2
		<<" "<<m_atraso
		<<" "<<m_t_subida
		<<" "<<m_t_descida
		<<" "<<m_t_ligada
		<<" "<<m_periodo
		<<" "<<m_ciclos<<endl;
}
void clearStream(ifstream& inputStream)
{
    inputStream.clear();

    // прочитаме останалата част от реда
    inputStream.ignore(MAX_LINE_LENGTH, '\n');
}
Esempio n. 17
0
int main()
{
	
	int lab_score, assignment_score, quiz_score, test_score; //declaring interger values
	char lab_grade, assignment_grade, quiz_grade, test_grade; //declaring character value
	float final_average; //declaring float vlaues
	class_heading();//calls the class heading
	myfile.open("infile.txt");
	myfile.ignore(133); //ignore function that ignores the title
	int count = 0;
	while (count < 20)	//while loop for the 20 students
	{
		count++; //count increment
		cout << "Student " << count << endl; //displays the student number
		lab_score = get_lab_data(); 
		assignment_score = get_assignment_data();
		quiz_score = get_quiz_data();
		test_score = get_test();
		lab_grade = compute_lab_grade(lab_score);
		assignment_grade = compute_assignment_grade(assignment_score);
		quiz_grade = compute_quiz_grade(quiz_score);
		test_grade = compute_test_grade(test_score);
		// Displays the grades 
		cout << "Students Lab Grade is : " << lab_grade << endl;
		cout <<  "Students Assignment Grade is : " << assignment_grade << endl;
		cout << "Students Quiz Grade is : " << quiz_grade << endl;
		cout << "Students Exam Grade is : " << test_grade << endl;
		final_average = ((10 * grade_calc_quiz(quiz_grade)) + (25 * grade_calc_assignment(assignment_grade)) + (30 * grade_calc_lab(lab_grade)) + (35 * grade_calc_test(test_grade))) / 100;
		cout << "Students Final Grade is : " << final_average_grade(final_average) << "\n" << endl;
	}
	system("pause");
}
Definition::Definition(ifstream& infile)
{
   string nextToken;
   infile >> nextToken;

   // throw away any junk before the open brace
   while (nextToken.compare ("{") != 0)
   {
      infile >> nextToken;
   }

   // The string after { is the nonterminal
   infile >> nextToken;
   // nextToken now contains this definition's title
   // save that
   nonterminal = nextToken;
#ifdef DEBUG
   cout << "Definition constructor called with nonterminal \n" << nonterminal << endl;
#endif

   // Now move on to start reading each production.
   bool finished = false;
   while (finished == false)
   {
      // each line is a "production"
      Production * p = new Production (infile);
      possibleExpansions.push_back (*p);
      
      // Check if there's a next line
      // Throw out any rubbish after the semi colon (
      infile.ignore (numeric_limits<streamsize>::max(), '\n');
      if (infile.peek () == '}') finished = true;
   }

}
Esempio n. 19
0
void ReadAndWriteFiles(ifstream& dataFileIn, AVLTreeType<elemT>& tree)
{
	int num;
	dataFileIn >> num;
    //While not end-of-file
    while(!dataFileIn.eof())
	{
		tree.insert(num);
		dataFileIn.ignore(81, '\n');
		dataFileIn >> num;
	} //End while

	//the three traverasls
	cout << "   1) The three traversals:";
	cout << endl << "       Inorder traversal:" << endl << "        ";
	tree.inorderTraversal();
	cout << endl << "       Preorder traversal:" << endl << "        ";
	tree.preorderTraversal();
	cout << endl << "       Postorder traversal:" << endl << "        ";
	tree.postorderTraversal();
	cout << endl;

	//height
	cout << "   2) The height of the tree: " << tree.treeHeight() << endl;

	//the number of nodes in the tree
	cout << "   3) The number of nodes in the tree: " << tree.treeNodeCount() << endl;

	//the number of leaves in the tree
	cout << "   4) The number of leaves in the tree: " << tree.treeLeavesCount() << endl;
}
Esempio n. 20
0
int
search(const map<string, int> &index, ifstream &data, const string& url, ostream &output)
{
	map<string, int>::const_iterator cit = index.find(url);
	if (cit == index.end())
	{
		output<<"Not Found!"<<endl;
		return -1;
	}
	data.seekg(cit->second);
	unsigned numoflinks;
	string surl;
	data>>surl>>numoflinks;
	data.ignore(numeric_limits<int>::max(), '\n');
	output<<surl<<'\t'<<numoflinks<<endl;
	for (unsigned i=0; i<numoflinks; i++)
	{
		string line;
		if (getline(data, line))
			output<<line<<endl;
		else
			break;
	}
	return 0;
}
Esempio n. 21
0
bool Game_Base::pRead_CCCard(ifstream& fin, Game_Base& base)
{
	GB_Card temp;

	temp.deck = true;

	getline(fin, temp.message);		// get the message
	fin >> temp.type;				// get the type
	fin.ignore(0x7fffffff, '\n');
	fin >> temp.value;				// get the value
	fin.ignore(0x7fffffff, '\n');

	// push the constructed entry into the data array
	base.fCards.push_back(temp);

	return true;
}
Esempio n. 22
0
void 	ProbData::loadData(ifstream& Infile)
{
	string	TempString;
	PCol	TempVect;
	string  Chillin;
	double  TempDouble; 
	unsigned col = 0;
	
// Get Header Line and....do nothing with it.
	Infile.ignore(10000,'\n');

	Chillin = " ";
//	TempVect.clear();

	// Copy first line of data into Chillin
	getline(Infile, Chillin, '\n');

	// Copy Chillin into FullLine
	std::istringstream FullLine(Chillin.c_str());

	// Ignore the header column
	FullLine.ignore(1000, '\t');

	// Read the first row and create a vector of vectors
	while(FullLine >> TempString)
	{
		TempVect.clear();
		TempDouble = atof(TempString.c_str());
		TempVect.push_back(TempDouble);
		ProbMat.push_back(TempVect);
	}	

	int row = 0;
	while (!Infile.eof())
	{
		col = 0;
		Chillin = " ";
		TempVect.clear();
		
		getline(Infile, Chillin, '\n');
		istringstream FullLine(Chillin.c_str());
		FullLine.ignore(1000, '\t');

		while(FullLine >> TempString)
		{
			TempDouble = atof(TempString.c_str());
			ProbMat[col].push_back(TempDouble);
			if (col > 0) {
				if(ProbMat[col].size() != ProbMat[col-1].size()) {
					printf("FUNNY, FUNNY HERE!: %d, %d\n", row, col);
					assert(false);
				}
			}
			col++;
		}
		row++;
	}
}
Esempio n. 23
0
//SIN (<nivel contínuo> <amplitude> <frequencia (Hz)> <atraso> <fator de atenuação> <ângulo> <número de ciclos>)
void Tensao::carregaParamSIN(ifstream &arq)
{
	int i = 0;
	while(arq.good() && arq.peek() != '\n')
	{
		//ignora os parenteses
		if (arq.peek() == ' ' || arq.peek() == '(' || arq.peek() == ')')
		{
			arq.ignore();
			continue;
		}
		switch(i)
		{
			case 0: 
				arq >> m_DC;
				break;
			case 1: 
				arq >> m_amplitude;
				break;
			case 2: 
				arq >> m_freq;
				break;
			case 3: 
				arq >> m_atraso;
				break;
			case 4: 
				arq >> m_atenuacao;
				break;
			case 5: 
				arq >> m_angulo;
				break;
			case 6: 
				arq >> m_ciclos;
				break;
			default:
				arq >>m_ignora;
				break;
		}
		i++;
	}
	if(i!=7)
	{
		cout<< m_nome <<" SIN: Numero de parametros errado" << i << "/7"<<endl;
		arq.close();
		m_erro = true;
	}

	cout<<m_nome<<" SIN:"<<m_nome_a<<" "<<m_nome_b
		<<" "<<m_DC
		<<" "<<m_amplitude
		<<" "<<m_freq
		<<" "<<m_atraso
		<<" "<<m_atenuacao
		<<" "<<m_angulo
		<<" "<<m_ciclos<<endl;

}
Esempio n. 24
0
void CascadeClassifier::ReadFromFile(ifstream& f)
{
    Clear();
    f>>count;
    f.ignore(256,'\n');
    ac = new AdaBoostClassifier[max_nodes];
    ASSERT(ac!=NULL);
    for(int i=0; i<count; i++) ac[i].ReadFromFile(f);
}
Esempio n. 25
0
/*VARIABLES FUNCTION Define: READS AND STORES VARIABLES*/
string VARIABLES::Define(ifstream &Input) {
  //DECLARE LOCAL VARIABLES
  string Read_Next(ifstream &Input);
  string str;
  int i;
  char c;
  const int n = 7;
  int delim[n] = {9,10,13,32,44,61,124};/*{'\t','\n','?CR?',' ',',','=','|'}*/


  //GET VARIABLE NAME (WITHOUT LETTING Read_Next TRY TO REPLACE)
  str.clear();
  while (Input.get(c)) {
    //Check for comments
    if(int(c)=='%') {
      Input.ignore(10001, '\n');
      continue;
    }
    //Check for deliminators
    for(i=0;i<n;i++) {
      if(int(c)==delim[i]) {
        i=-1;
        break;
      }
    }
    if(i!=-1) {str += c;break;}
  }
  if(int(c)!='$') {
    //Not a valid variable name (return)
    Input.putback(c);
    return(Read_Next(Input));
  }
  str = Read_Next(Input);//NOTE: this allows deliminators between '$' and varaible name
  str.insert(0, "$");


  //FIND VARIABLE TO REDEFINE IT OR FIND UNUSED SLOT
  VARIABLES *var = this;
  while(var!=var->next) {
    if(str.compare(var->symb)==0) {break;}
    var = var->next;
  }


  //STORE SYMBOL AND VALUE
  var->symb = str;
  str = Read_Next(Input);
  i = int(str[0]);
  if( (i<43)||(i>57)||(i==44)||(i==47) ) {//Check if a number is present
    Log <<str<<" is not a valid expression for variable "<<var->symb<<endl;
    exit(0);
  }
  var->value = atof(str.c_str());
  if(var==var->next) {var->next = new VARIABLES();}//Allocate memory for next variable

  return(Define(Input));
}
Esempio n. 26
0
size_t FileSize(ifstream& is) {
  const streampos pos = is.tellg();
  is.clear();
  is.seekg(is.beg);
  is.ignore(numeric_limits<streamsize>::max());
  const size_t size = is.gcount();
  is.clear(); //clear EOF (set by ignore)
  is.seekg(pos);
  return size;
}
Esempio n. 27
0
int main()
{	
	insert();

	int N;
	ifs >> N;
	ifs.ignore();	//\n
	for(int c=0;c<N;c++){
		Sol(c);
	}
}
Esempio n. 28
0
int main()
{
    long n,m;
    in>>n>>m;
    in.ignore(1000, '\n');
    for(int k=0; k<2; k++)
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
            {
                uchar ch;
                in>>ch;
                switch(ch)
                {
                case 'X':
                case '/':
                    field[(i+1)*(m+1)+j] |= 1<<(4*k);
                    field[i*(m+1)+j+1] |= 1<<(4*k+2);
                    if(ch=='/') break;
                case '\\':
                    field[i*(m+1)+j] |= 1<<(4*k+1);
                    field[(i+1)*(m+1)+j+1] |= 1<<(4*k+3);
                }
            }
    long dx[]= {-m,m+2,m,-m-2};
    long count=0;
    for(long x=0; x<(n+1)*(m+1); x++)
        if(lab[x]==0)
        {
            long c=0;
            long qb=0, qe=0;
            que[qe++]=(uint)x;
            lab[x]=1;
            while(qb!=qe)
            {
                long cx=que[qb++];
                long cc=0;
                for(int k=0; k<8; k++)
                    if((field[cx] & (1<<k)) != 0)
                    {
                        cc+= k<4 ? 1 : -1;
                        long nx=cx+dx[k%4];
                        if(lab[nx]==0)
                        {
                            que[qe++]=(uint)nx;
                            lab[nx]=1;
                        }
                    }
                c+=labs(cc);
            }
            if(qb>1) count += c==0 ? 1 : c/2;
        }
    out<<count;
    return 0;
}
void readResource(ifstream& fileInput, Scheduling& task){

	string line;
	while(getline(fileInput,line,'=')){
		if(line == "ProcessFile"){
			getline(fileInput,task.ProcFile);
		}
		else if(line == "IOdelay"){
			fileInput >> task.ioDelay;
			fileInput.ignore(1);                          //ignore moves the input stream pointer past the '\n' char.
		}
		else if(line == "ContextSwitchDelay"){
Esempio n. 30
0
// Loads questions from file into "Question" array
void Question::loadQues()
{
	int i, j;
	for(i=0; i<totNoOfQues; i++)
		{
		quiz.getline(Quiz[i].q, 200);
		for(j=0; j<4;j++)
			quiz.getline(Quiz[i].opt[j], 50);
		quiz>>Quiz[i].ans;
		quiz.ignore(2);
		}
}