Ejemplo n.º 1
0
void Display::loadWorldServer(stringstream& msg)
{
	string text;
	msg >> text;
	while (text!="End")
	{
		if (text == "Tile")
		{
			msg.clear();
			Tile tile;
			tile.deserialize(msg);
			m_map[tile.getPos()] = tile;
		}
		if (text == "Player")
		{
			msg.clear();
			Player player;
			player.deserialize(msg);
			game::pHandler.addPlayer(player);
		}
		text = "End";
		msg.clear();
		msg >> text;
	}

	reloadAll_ = true;
	isLoaded_ = true;
}
Ejemplo n.º 2
0
int main() {
    scanf("%d\n\n", &N);
 
    for(int T = 0;; T++) {
        if(T > 0) printf("\n");
 
        getline(cin, line);
        ss.clear();
        ss.str(line);
        elements.clear();
        while(ss >> a)
            elements.push_back(a);
        sort(elements.begin(), elements.end());
 
        getline(cin, line);
        ss.clear();
        ss.str(line);
        adj.clear();
        adj.resize(256);
        while(ss >> a >> b >> c)
            adj[a].push_back(c);
 
        if(!dfs(""))
            printf("NO\n");
        if(!getline(cin, line)) break;
    }
}
Ejemplo n.º 3
0
void rysuj_plansze()
{
    al_clear_to_color(al_map_rgb(255,247,255));
	al_draw_filled_rounded_rectangle(square_x, square_y, square_x + square_size, square_y + square_size, square_size/50, square_size/50, al_map_rgb(188,172,159));
	

	for(int a = 0; a < 4; a++){
		for(int b = 0; b < 4; b++){
			al_draw_filled_rounded_rectangle(square_x + a * break_size + break_size + a * tile_size, square_y + b * break_size + break_size + b * tile_size, square_x + a * break_size + break_size + a * tile_size + tile_size, square_y + b * break_size + break_size + b * tile_size + tile_size, square_size/50, square_size/50, al_map_rgb(205,191,178));
		}	
	}

	al_draw_text(howtoarial, al_map_rgb(112,108,99), square_x/2, square_y + tile_size - break_size, ALLEGRO_ALIGN_CENTRE, howto.c_str());
	al_draw_text(titlearial, al_map_rgb(112,108,99), square_x/2, square_y - break_size * 2, ALLEGRO_ALIGN_CENTRE, title.c_str());

	new_game.draw();//	Rysowanie przycisku New game

	undo.draw();//	Rysowanie przycisku Undo

	
//
//	Rysowanie okienka Score
//	
	al_draw_filled_rounded_rectangle(square_x + square_size + break_size * 4, square_y + break_size, screen_w - break_size * 4, square_y + tile_size + break_size, square_size/50, square_size/50, al_map_rgb(112,108,99));
	al_draw_text(scorearial, al_map_rgb(255,247,255), square_x + square_size + square_x/2, square_y + break_size * 2, ALLEGRO_ALIGN_CENTRE, scoretxt.c_str());
	ss.clear();
	ss << score;
	ss >> scorenum;
	al_draw_text(scorearial, al_map_rgb(255,247,255), square_x + square_size + square_x/2, square_y + break_size + tile_size/2, ALLEGRO_ALIGN_CENTRE, scorenum.c_str());

//
//	Rysowanie okienka Highscore
//
	al_draw_filled_rounded_rectangle(square_x + square_size + break_size * 4, square_y + break_size * 2 + tile_size, screen_w - break_size * 4, square_y + tile_size * 2 + break_size * 2, square_size/50, square_size/50, al_map_rgb(112,108,99));
	al_draw_text(scorearial, al_map_rgb(255,247,255), square_x + square_size + square_x/2, square_y + break_size * 3 + tile_size, ALLEGRO_ALIGN_CENTRE, highscoretxt.c_str());
	ss.clear();
	ss << highscore;
	ss >> highscorenum;
	al_draw_text(scorearial, al_map_rgb(255,247,255), square_x + square_size + square_x/2, square_y + break_size * 2 + tile_size/2 + tile_size, ALLEGRO_ALIGN_CENTRE, highscorenum.c_str());

//
//	Rysowanie kafelków
//	
	
	for(int a = 0; a < 4; a++){
		for(int b = 0; b < 4; b++){
			if(tiles[a][b].number > 0){
				al_draw_filled_rounded_rectangle(square_x + a * break_size + break_size + a * tile_size + 10 * tile_size/20 - tiles[a][b].animation_size * tile_size/20, square_y + b * break_size + break_size + b * tile_size + 10 * tile_size/20 - tiles[a][b].animation_size * tile_size/20, square_x + a * break_size + break_size + a * tile_size + tile_size - 10 * tile_size/20 + tiles[a][b].animation_size * tile_size/20, square_y + b * break_size + break_size + b * tile_size + tile_size - 10 * tile_size/20 + tiles[a][b].animation_size * tile_size/20, square_size/50, square_size/50, al_map_rgb(tiles[a][b].r,tiles[a][b].g,tiles[a][b].b));
				ss.clear();
				ss << tiles[a][b].number;
				ss >> text;
				if(tiles[a][b].number > 4){
					al_draw_text(arial, al_map_rgb(255,247,255), square_x + tile_size * a + break_size * a + break_size + tile_size/2, square_y + tile_size * b + break_size * b + break_size + tile_size/2 - 25, ALLEGRO_ALIGN_CENTRE, text.c_str());
				}else{
					al_draw_text(arial, al_map_rgb(125,114,110), square_x + tile_size * a + break_size * a + break_size + tile_size/2, square_y + tile_size * b + break_size * b + break_size + tile_size/2 - 25, ALLEGRO_ALIGN_CENTRE, text.c_str());
				}
			}
		}	
	}
Ejemplo n.º 4
0
void Motor::STOP_TALKING_TO_MOTOR( stringstream& cmd)
{
    cmd.clear();
    cmd << "{0" << CRLF;
    SendCommand(cmd);
    cmd.str("");
    cmd.clear();
}
Ejemplo n.º 5
0
void Motor::TALK_TO_MOTOR(stringstream& cmd)
{
    cmd.clear();
    cmd << "{" << MotorID << CRLF;
    SendCommand(cmd);
    cmd.str("");
    cmd.clear();
}
int main () {
    int n1, n2;
    int idx = 0;
    while (1) {
        string inp;
        getline(cin, inp);
        ss.str("");
        ss.clear();
        ss.str(inp);
        ss >> n1;
        if (n1 == 0) break;
        cout<<"Run #"<<++idx<<": ";
        vector <string> set1(n1);
        for (int i = 0;i < n1; i++) {
            getline(cin, set1[i]);
        }
        getline(cin, inp);
        ss.str("");
        ss.clear();
        ss.str(inp);
        ss >> n2;
        vector <string> set2(n2);
        for (int i = 0;i < n2;i++) {
            getline(cin, set2[i]);
        }
        bool flag = false;
        if (n1 == n2) {
            flag = true;
            for (int i = 0;i<n1;i++) {
                if (set1[i] != set2[i]) {
                    flag = false;
                    break;
                }
            }
        }
        if (flag) {
            cout<<"Accepted"<<endl;
        }
        else {
            string s1 = clean(set1);
            string s2 = clean(set2);
            if (s1 == s2) {
                cout<<"Presentation Error"<<endl;
            }
            else {
                cout<<"Wrong Answer"<<endl;
            }
        }
    }
    return 0;
}
Ejemplo n.º 7
0
void InfoPanel::showPanel()
{
    SDL_Rect background = {x, y, SCREEN_WIDTH, SCREEN_HEIGHT*0.25};
    SDL_FillRect(screen, &background, 0x000000);

    Render::UnfilledRect(screen, x, y, SCREEN_WIDTH, SCREEN_HEIGHT*0.25, 5, 0xffffff);


    s << h_offset << ", " << v_offset << ", " << currentFPS;
    SDL_Surface * t = TTF_RenderText_Blended( font, s.str().c_str(), {255, 255, 255} );
    Render::apply_surface(x+CELL_SIZE, y+CELL_SIZE, t, screen);
    s.str("");
    s.clear();

    if (p.get_selected_cell()->get_o() != NULL && p.get_selected_cell()->get_visible() == true)
    {
        t = TTF_RenderText_Blended( font, p.get_selected_cell()->get_o()->get_title().c_str(), {255, 255, 255});
        Render::apply_surface(x+CELL_SIZE, y+2*CELL_SIZE, t, screen);

        p.get_selected_cell()->get_o()->draw_ActionSurface();
    }
    else if (p.get_selected_cell()->get_visible() == false)
    {
        t = TTF_RenderText_Blended( font, "This cell is obscured by the fog of war", {255, 255, 255});
        Render::apply_surface(x+CELL_SIZE, y+2*CELL_SIZE, t, screen);
    }

    Render::UnfilledRect(screen, x+SCREEN_WIDTH*0.25, y, SCREEN_WIDTH*0.50, SCREEN_HEIGHT*0.25, 2, 0xffffff);

    SDL_FreeSurface(t);
    minmap->drawMap();
}
Ejemplo n.º 8
0
void printNode(stringstream& lineStream, NodeList& NList) {

	string Nodes, junk;
	int nodeID;

	lineStream >> nodeID;

		if(lineStream.fail()) {

			lineStream.clear();
			lineStream >> Nodes;
			if(lineStream.fail()) {
				cout << "Error: too few arguments" << endl;
				return;
			}

			if(Nodes != "all") {
				cout << "Error: invalid argument" << endl;
				return;
			}
                        
                        if(!endOfArgs(lineStream)) return;

			//if argument is "all", print all nodes
			cout << "Print: " << endl;
                        Node* current = NList.getNHead();
                        while(current != NULL) {
                            cout << *current;
                            current = current -> getNextN();
                        }

			return;

		}
Ejemplo n.º 9
0
/** @function detectAndDisplay */
void detectAndDisplay(Mat &frame)
{
  static vector<Rect> faces;
  static Mat frame_gray;

  cvtColor( frame, frame_gray, CV_BGR2GRAY );
  equalizeHist( frame_gray, frame_gray );

  //-- Detect faces
  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

  size_t tam = faces.size();
  for(size_t i = 0; i < tam; i++){
    Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );

    /// Transforma o valor da coodenada x do pixel central da face (int --> char *)
    ss.clear();
    ss << center.x;
    ss >> bytes;

    cout << bytes << endl;

    /// Envia o valor da coodenada x do pixel central da face para a porta serial do Arduino
    RS232_cputs(COM, bytes);

    /// Cria uma elipse em volta do pixel central da face para destacá-la
    //ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 255, 255 ), 4, 8, 0 );
  }

  /// Exibir a frame do vídeo que acabou de ser processada
  //imshow( window_name, frame );
 }
Ejemplo n.º 10
0
	int TablePaser::GetColumn(stringstream& ss_str, std::basic_istream<char>& in_put, string& column)
	{
		column = "";
		if (ss_str.eof())
			return -1;
		char cur_char[2];
		cur_char[1] = 0;
		char separator = '	';

		if (ss_str.get(cur_char[0]).eof())
			return 1;
		if (cur_char[0] == '	')
			return 1;
		else if (cur_char[0] == '"')
			separator = '"';
		else
			column += string(cur_char);


		while (1)
		{
			if (ss_str.eof())
			{
				if (separator == '"')
				{
					if (in_put.eof())
						return 0;

					column += string("\n\0");
					ss_str.clear();
					in_put.getline(LineData, LINE_DATA_MAX);
					ss_str << LineData;
				}
				else
					return 0;
			}
			ss_str.getline(LineData, 4096, separator);
			column += LineData;
			//column.append(LineData);
			if (ss_str.eof())
				continue;
			if (separator == '	')
				return 1;
			else if (separator == '"')
			{
				if (ss_str.eof())
					return 0;
				ss_str.get(cur_char[0]);
				if (ss_str.eof())
					return 1;
				else if (cur_char[0] == '	')
					return 1;
				else if (cur_char[0] != separator)
					separator = '	';
				//column.push_back(cur_char);
				column += string(cur_char);
			}
		}
		return -1;
	}
Ejemplo n.º 11
0
void printDEBUG(stringstream& s)
{
    if (DEBUG == 1)
    {
        cout << s.str();
    }
    s.clear();
}
int integer(string s) {
    int a;
    ss.str("");
    ss.clear();
    ss.str(s);
    ss >> a;
    return a;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
    int seed=time(NULL);
    if(argc > 1)
    {
        ss.clear();
        ss<<argv[1];
        ss>>seed;
    }
Ejemplo n.º 14
0
QByteArray Motor::SendCommand(stringstream& cmd)
{
    m_pPort->write(cmd.str().c_str(),cmd.str().length());
    m_pPort->waitForBytesWritten(0);
    //qDebug() << "Sent command " << cmd.str().c_str();
    cmd.str("");
    cmd.clear();
    delay(10);
    return  m_pPort->readLine();
}
Ejemplo n.º 15
0
void mem_logger_print(avr_t* avr, const int level, const char * format, va_list args)
{
//    va_list args;
//    va_start(args, format);
    char buff[100];
    vsnprintf(buff, 100, format, args);
    oss.clear();
    oss << buff;
//    va_end(args);
}
void print ( ofstream & o, stringstream & txt, bool only2file ) {
    cout.precision ( 3 );
    o.precision ( 3 );
    if ( !only2file ) {
        cout << txt.str ();
    }    
    o << txt.str ();
    txt.str ( string () );
    txt.clear ();
    return;
}
Ejemplo n.º 17
0
vector <string> readstr(string s) {
    vector <string> res;
    string ele;
    ss.str("");
    ss.clear();
    ss.str(s);
    while (ss >> ele) {
        res.push_back(ele);
    }
    return res;
}
Ejemplo n.º 18
0
vector <int> readints(string s) {
    vector <int> res;
    int ele;
    ss.str("");
    ss.clear();
    ss.str(s);
    while (ss >> ele) {
        res.push_back(ele);
    }
    return res;
}
Ejemplo n.º 19
0
string printOptimalParents(int i, int j) {
    stream.clear();
    if (i == j){
        string s = "A";
        string str;
        stream << i;

        stream >> str;
        s += str;
        return s;
    }
Ejemplo n.º 20
0
bool parseError(stringstream& ss, string errMessage, int offset = 0) {
    ss.clear();
    int colNo = (int) ss.tellg();
    if (colNo <= 0) colNo = 1;
    colNo += offset;
    cerr 
    //   << ss.str() << endl
         << setw(colNo) << right << "^" << endl
         << "Parse error: col #" << colNo << ", " << errMessage << endl;
    return false;
}
Ejemplo n.º 21
0
/************************************************************************
 * solveTheProblem							*
 *	Assumes the equations and variables have already been entered	*
 *	solves the problem, writing the solution in TEMP_FILE, 		*
 *	including the tags and problem statements if the problem was	*
 *	not completely solved.						*
 *   Then it opens the file for reading, and returns the first line	*
 *	[does not close file]						*
 ************************************************************************/
const char* solveTheProblem() {
  int k;

  if (isFirst) throw string("solveTheProblem called before initialization");
  try {
    // reset the buffer to be empty
    resultBuffer.str(string());
    if(resultBuffer.good()) {
      numsols->assign(canonvars->size(),HUGE_VAL);
      if (solveeqs(resultBuffer)) {
	// should we do checking of solution here?
	bool discrep = false;
	for (k = 0; k < canoneqf->size(); k++) {
	  if (checksol((*canoneqf)[k],numsols,RELERR) > 1) {
	    if (!discrep) {
	      resultBuffer << "<DISCREPANCIES>" << endl;
	      discrep = true;
	    }
	    resultBuffer << (*canoneqf)[k]->getInfix() << endl;
	  }
	} // loop over equations to check
	dimchkeqf(resultBuffer);
	// end of "should we do checking of solution here?"
      }
    } 
    else throw string("unable to create solution buffer");
  } 
  catch (string message) { throw message; } 
  catch (...) { throw string("solveTheProblem went boom!!"); }

  // this would be a good place to insert checksol ? or after returning
  // solution, in solveMoreOfTheProblem ?
  try {
    resultBuffer.clear();
    resultBuffer.seekg(0);
    int tk;
    try { tk = resultBuffer.eof(); } 
    catch (...) { throw string("eof?!?"); }
    if (! tk) {
      string t;
      try { t = getaline(resultBuffer); }
      catch (...) { throw string("getaline fails???"); }
      try { sprintf(lzbfr, "%s", t.c_str()); } 
      catch(...) { throw string("copy is wrong??"); }
      return lzbfr;
    } 
    else return error[4];
  } 
  catch (string message) { throw message; } 
  catch (...) { throw string("Read went bad!!"); }
  return error[3];
}
Ejemplo n.º 22
0
Archivo: 1044.cpp Proyecto: zxc0328/PAT
string marsToEarth(string marsStr) {
	vector<string> marsVec;
	int position = 0;
  position = marsStr.find(" "); 
  if (position > 0) {
  	marsVec.push_back(marsStr.substr(0,position));
  	marsVec.push_back(marsStr.substr(position + 1));
  }else{
  	marsVec.push_back(marsStr);
  }
  vector<int> num13;
  	if (marsVec.size() == 2){
  		for (int i=0;i<12;i++){
  			if (marsVec[0] == marsHigh[i]){
  				num13.push_back(i+1);
  			}
  		}
  		if (marsVec[1] == marsZero){
  			num13.push_back(0);
  		}
  		for (int i=0;i<12;i++){
  			if (marsVec[1] == marsLow[i]){
  				num13.push_back(i+1);
  			}
  		}
  	}else{
  		for (int i=0;i<12;i++){
  			if (marsVec[0] == marsHigh[i]){
  				num13.push_back(i+1);
  				num13.push_back(0);
  			}
  		}
  		if (marsVec[0] == marsZero){
  			num13.push_back(0);
  			num13.push_back(0);
  		}
  		for (int i=0;i<12;i++){
  			if (marsVec[0] == marsLow[i]){
  				num13.push_back(0);
  				num13.push_back(i+1);
  			}
  		}
  	}
  int num10;
  string output;
  num10 = trans13To10(num13);
  ss.clear();
	ss << num10;
	ss >> output;
  return output;
}
Ejemplo n.º 23
0
/************************************************************************
 * solveMoreOfTheProblem						*
 *	reads one line from the opened solution file, 			*
 *	if that line is empty, closes file, returns nil			*
 *	if not, returns it						*
 *	if EOF, closes file and returns nil				*
 *	I don't understand when is returns "So far so good"		*
 ************************************************************************/
const char* solveMoreOfTheProblem() {
  try {
    if (! resultBuffer.eof()) {
      string t = getaline(resultBuffer);
      if (t.size() == 0) {
        resultBuffer.clear();
	return error[4];	// if checksol after returning sol, here+below
      } // end of if line empty, which closes and returns
      else sprintf(lzbfr, "%s", t.c_str());
      return lzbfr;
    } // end of not eof. 
    else {
      resultBuffer.clear();
      return error[4];	// if checksol after returning sol, here and above
    }
  } catch (string message) {
    resultBuffer.clear();
    throw message;
  } catch (...) {
    resultBuffer.clear();
      throw string("More went bad!!");
  }
  return error[3];
}
Ejemplo n.º 24
0
bool treeTrace( stringstream &ss, vector<int> &T, int currSum )
{
	if( ss.rdbuf()->in_avail() == 0 )
		return false;
	char leftBracket;
	ss >> leftBracket;
	int integer;
	ss >> integer;
	bool leftTree;
	if( ss.fail() )
	{
		ss.clear();
		char otherBracket;
		ss >> otherBracket;
		return false;
	}
Ejemplo n.º 25
0
Archivo: 1044.cpp Proyecto: zxc0328/PAT
vector<int> trans10To13(string num10) {
	vector<int> num13Int;
	int num10Int;
	ss.clear();
	ss << num10;
	ss >> num10Int;
	int ans = num10Int;
	int remain;

	while(ans != 0){
		remain = ans%13;
		num13Int.push_back(remain);
		ans = ans/13;
	}
	return num13Int;
}
Ejemplo n.º 26
0
void test2() {
	cout << "sub: thread test" << endl;
	load("../sub/bin/main.out");
	pipeinit(&in, &out, &infl, &outfl);
	// thread test
	thread t(pipethread);
	string s;
	while (cin >> s) {
		if (infl == 0)  in.str(""), in.clear();
		in << s << " ";
		infl = 1;
	}
	infl = -1;
	t.join();
	// end
	unload();
}
Ejemplo n.º 27
0
int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	//cout<<fixed<<setprecision(10); cerr<<fixed<<setprecision(10); //cout.ignore(INT_MAX, ' '); //cout << setfill('0') << setw(5) << 25
	
	while (getline(cin, line), line.length()) {
		ss.clear();
		ss<<line;
		ss>>a>>b;
		dic[b] = a;
	}
	while (cin>>b) {
		if (dic.find(b) == dic.end()) cout<<"eh\n";
		else cout<<dic[b]<<"\n";
	}
	
	return 0;
}
Ejemplo n.º 28
0
bool my_getline(istream& is, string& line_buffer)
{
	static stringstream sstream;
	static string firstword;

	firstword = "";

	getline(is, line_buffer);
	sstream.str(line_buffer);
	sstream.clear();
	sstream >> firstword;

	if(firstword.compare("UQMD")==0)
		return true;
	else
		return false;
}
Ejemplo n.º 29
0
bool readInputFile(string inputFilePath) {
  ifstream inFile(inputFilePath.c_str());
  string input_line;

  /* Read in the MBBs */

  while (std::getline(inFile, input_line)) {
    mystr.str(input_line);
    mystr.clear();

    SpatialObject *obj = new SpatialObject(0, 0, 0, 0);
    mystr >> id >> obj->left >> obj->bottom >> obj->right >> obj->top;
    listAllObjects.push_back(obj);
  }


  return true;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in_2289.txt","r",stdin);
#endif
	while(scanf("%d%d",&n,&m)&&n)
	{
		memset(mat,false,sizeof(mat));
		for(int i=0;i<n;++i)
		{
			scanf("%s",&buf);
			gets(buf);
			str.assign(buf);
			ss.clear();
			ss<<str;
			int g;
			while(1)
			{
				ss>>g;
				mat[i][g]=true;
				if(ss.eof())
				{
					break;
				}
			}
		}
		l=1;
		r=n;
		while(l<=r)
		{
			mid=(l+r)>>1;
			if(Check())
			{
				r=mid-1;
			}
			else
			{
				l=mid+1;
			}
		}
		printf("%d\n",l);
	}
	return 0;
}