Example #1
0
string Text::toString(int n)
{
	static ostringstream out;
	out.str("");
	out.clear();
	out << n;
	string newStr = out.str();
	return newStr;
}
Example #2
0
string header::double2str(const double in, const double missing_value)
{
	if (in == missing_value)
		return ".";
	else
	{
		static ostringstream out;
		out.str(""); out.clear();
		out << in;
		return out.str();
	}
}
void
CSipResponse::BuildPacket() throw(CSipException *)
{
	if(GetCommand().length() == 0)
		throw(new CSipException(SipError::UNSUPPORTED_COMMAND));
	//
	static ostringstream response;
	response.clear();
	response.str("");
	//
	if(GetCSeqCommand().length() == 0)
		SetCSeqCommand(GetCommand());
	//
	response << "SIP/2.0" << GetStatusCode() << GetStatus() << " SIP/2.0\r\n"
			 << "Via: SIP/2.0/UDP " << GetCallerAddress() << ":" << GetCallerPort()
			 << ";branch=" << GetBranch() << "\r\n"
			 << "Contact: <sip:" << GetCallerId() << "@" << GetCallerAddress()
			 << ":" << GetCallerPort() << ">;expires=" << GetExpires() << "\r\n"
			 << "Call-ID: " << GetCallId() << "\r\n"
			 << "Cseq: " << GetCSeq() << " " << GetCSeqCommand() << "\r\n";
	//
	if(GetServer().length() > 0)
		response << "Server: " << GetServer() << "\r\n";
	//
	// To field:
	response << "To: ";
	if(GetCalleeScreenName().length() > 0)
		response << "\"" << GetCalleeScreenName() << "\"";
	//
	response << "<sip:" << GetCalleeId() << "@" << GetSipServerAddress() << ">";
	response << ";tag=" << GetCalleeTag() << "\r\n";
	//
	// From field:
	response << "From: ";
	if(GetCallerScreenName().length() > 0)
		response << "\"" << GetCallerScreenName() << "\"";
	//
	response << "<sip:" << GetCallerId() << "@" << GetCallerAddress() << ">"
			 << ";tag=" << GetCallerTag() << "\r\n";
	//
	response << "Allow: REGISTER, INVITE, ACK, CANCEL, BYE\r\n";
	//
	if(GetContent().length() > 0)
	{
		response << "Content-Length: " << GetContent().length() << "\r\n"
				 << "Content-Type: " << GetContentType() << "\r\n"
				 << "\r\n" << GetContent();
	}
	else
		response << "\r\n";
	//
	SetBuffer(response.str().c_str(), response.str().length());
}
Example #4
0
/**
 * This method will execute the given codeStream passed in.
 * @param codeStream stream of C++ code that contains a compilable main() method
 * @param force_rollback if set, this will rollback any changes made to the code
 *                       during execution. This is used for the '!' and '@'
 *                       commands.
 * @return 0 if compilation is successful
 */
int execute(ostringstream* codeStream, bool force_rollback) {
  int output = 0;

  //Backup the main file before it gets overwritten by the code stream.
  backup_file(sMainPath);

  //Write the code stream to the main file.
  ofstream outputFile;
  outputFile.open(sMainPath.c_str());
  outputFile << codeStream->str();
  outputFile.close();

  //Backup the current executable before compiling.
  backup_file(sExecPath);

  //Attempt to compile
  output = compile();

  if (output == 0) {
    //If compiling is successful, get the full path of the executable and send
    //it to system() to compile.
    char full_path[256];
    realpath(sExecPath.c_str(), full_path);
    system(full_path);
  }

  //Rollback if force flag is set, or if compilation failed.
  if ((force_rollback) || (output != 0)) {
    rollback_file(sMainPath);
    output=1;
  }

  //Rollback the executable after it is done.  This is to prevent a project
  //executable from getting modified.  This only applies when the console in
  //running in a project directory.
  rollback_file(sExecPath);

  //Reset variables now that the code was executed.
  sCodeBuffer.str(""); //Clear out the code buffer to allow new user input.
  sCodeBuffer.clear();
  sCodeType = MAIN_CODE; //Reset the code type to its default.
  sBraceCount = 0; //Ensure the brace count is zero.  A reload! can force an
  //execution even if the brace count is not zero.

  //Ensure a newline is printed since the output may not have one.
  cout << "\n";

  return output;
}
Example #5
0
int main(int argc, char* argv[]) {

	int N;
	int score;

	if (argc == 1)
	{
		cout << "please! input number" << endl;
		return 0;
	}

	N = atoi(argv[1]);

	if (N > MAX)
	{
		cout << "overflow! maximum size is 100000" << endl;
		return 0;
	}

	else if (N < 1)
	{
		cout << "underflow! minimum size is 1" << endl;
		return 0;
	}



	//배열에 값 넣기
	for (int i = 0; i < MAX; i++) {
		oss.str(""); oss.clear();
		oss.width(5);
		oss.fill('0');
		oss<<i;
		workerNum[i]= "NT" + oss.str();
	}

	//셔플함수 호출
	shuffleNumber();

	for (int i = 0; i < N; i++) {
		score = mt_rand() % SCORE;
		cout << workerNum[i] << " " << score << endl;
	}

	return 0;
}
Example #6
0
/**
 * This method will reload the main file back to its original state by loading
 * the configuration template.
 * @return 0 if execution was successful
 */
int reload() {
  cout << "Reloading...\n";

  //If the template doesn't exist, create a new one.
  if (!file_exists(sConfigPath.c_str()))
    create_config_template();

  //Load the template data into a stream.
  ostringstream stream;
  load_config_template(&stream);

  //Reset the dump buffer.
  sDumpBuffer.str("");
  sDumpBuffer.clear();

  //Execute the stream to verify if the reload was successful.
  return execute(&stream, false);
}
int main()
{
    int T, N;
    long long res = 0;

    cin >> T;
    while (T--) {
        convert.str("");
        convert.clear();
        cin >> N;
        res = (((((N *  567) / 9) + 7492) * 235)/ 47) - 498;
        convert << res;
        
        string p = convert.str();
        
        cout << p.at(p.length() - 2) << endl;
        res = 0;
    }

    return 0;
}
Example #8
0
void geticonsql(ostringstream& o, const pokemon_obj * pkm, int generation)
{
    string formid;
    if(pkm->ivs.isegg)
    {
        if(int(pkm->species) == int(Species::manaphy))
        {
            o << "SELECT image FROM icons_male WHERE (identifier = \"egg-manaphy\")"; // It's a Manaphy egg.
        }
        else
        {
            o << "SELECT image FROM icons_male WHERE (identifier = \"egg\")"; // It's as regular egg.
        }
    }
    else
    {
        //        int formint = pkm->forms.form;
        if(int(pkm->species) == int(Species::arceus))
        {
            //            formint = 0;
            formid = "";
        }
        else
        {
            o
                    << "SELECT pokemon_forms.form_identifier "
                    << "FROM   pokemon_forms "
                    << "       INNER JOIN pokemon_form_generations "
                    << "               ON pokemon_forms.id = pokemon_form_generations.pokemon_form_id "
                    << "       INNER JOIN pokemon "
                    << "               ON pokemon_forms.pokemon_id = pokemon.id "
                    << "WHERE  ( pokemon_form_generations.generation_id = " << generation << " ) "
                    << "       AND ( pokemon.species_id = " << (int)(pkm->species) << " ) "
                    << "       AND ( pokemon_form_generations.game_index = " << (int)(pkm->forms.form) << " ) ";
            //            << "SELECT pokemon_forms.form_identifier "
            //            << "FROM   pokemon_form_names "
            //            << "       INNER JOIN pokemon_forms "
            //            << "               ON pokemon_form_names.pokemon_form_id = pokemon_forms.id "
            //            << "       INNER JOIN pokemon "
            //            << "               ON pokemon_forms.pokemon_id = pokemon.id "
            //            << "WHERE  ( pokemon.species_id = " << (int)(pkm.species) << " ) "
            //            << "       AND ( pokemon_form_names.local_language_id = " << langid << " ) "
            //            << "       AND ( pokemon_forms.form_order = " << (int)(pkm.forms.form) << " + 1 ) ";
            formid = getastring(o);
            o.str("");
            o.clear();
        }
        o << (int)(int(pkm->species));
        if(formid != "")
        {
            o << "-" << formid;
        }
        formid = o.str().c_str();
        o.str("");
        o.clear();
        string tgender = "";
        if(((int(pkm->species) == 521) | (int(pkm->species) == 592) | (int(pkm->species) == 593)) && (calcpkmgender(pkm) == Genders::female))
        {
            tgender = "fe";
        }
        tgender += "male";
        if(int(pkm->species) == int(Species::keldeo))
        {
            switch(pkm->forms.form)
            {
            case 0:
                formid = "647-regular";
                break;
            case 1:
                formid = "647-resolution";
                break;
            }
        }
        if(int(pkm->species) == int(Species::kyurem) && pkm->forms.form != 0)
        {
            if(pkm->forms.form == 1)
            {
                formid = "646-white";
            }
            else
            {
                formid = "646-black";
            }
        }
        o << "SELECT image FROM icons_" << tgender << " WHERE (identifier = \"" << formid << "\")";
    }
}
Example #9
0
void getspritesql(ostringstream& o, const pokemon_obj * pkm, int generation)
{
    o
            << "SELECT pokemon_forms.form_identifier "
            << "FROM   pokemon_forms "
            << "       INNER JOIN pokemon_form_generations "
            << "               ON pokemon_forms.id = pokemon_form_generations.pokemon_form_id "
            << "       INNER JOIN pokemon "
            << "               ON pokemon_forms.pokemon_id = pokemon.id "
            << "WHERE  ( pokemon_form_generations.generation_id = " << generation << " ) "
            << "       AND ( pokemon.species_id = " << (int)(pkm->species) << " ) "
            << "       AND ( pokemon_form_generations.game_index = " << (int)(pkm->forms.form) << " ) ";
    //            << "SELECT pokemon_forms.form_identifier "
    //            << "FROM   pokemon_form_names "
    //            << "       INNER JOIN pokemon_forms "
    //            << "               ON pokemon_form_names.pokemon_form_id = pokemon_forms.id "
    //            << "       INNER JOIN pokemon "
    //            << "               ON pokemon_forms.pokemon_id = pokemon.id "
    //            << "WHERE  ( pokemon.species_id = " << (int)(pkm.species) << " ) "
    //            << "       AND ( pokemon_form_names.local_language_id = " << langid << " ) "
    //            << "       AND ( pokemon_forms.form_order = " << (int)(pkm.forms.form) << " + 1 ) ";
    string formid = getastring(o);
    o.str("");
    o.clear();
    o << (int)(pkm->species);
    if(formid != "")
    {
        o << "-" << formid;
    }
    formid = o.str().c_str();
    string tshiny = "";
    if(getpkmshiny(pkm))
    {
        tshiny = "shiny";
    }
    else
    {
        tshiny = "normal";
    }
    if(int(pkm->species) == int(Species::keldeo))
    {
        switch(pkm->forms.form)
        {
        case 0:
            if(tshiny == "shiny")
            {
                formid = "647-regular";
            }
            else
            {
                formid = "647-ordinary";
            }
            break;
        case 1:
            formid = "647-resolution";
            break;
        }
    }
    o.str("");
    o.clear();
    string tgender = "";
    if((pkmhasgenddiff(pkm) && (calcpkmgender(pkm) == Genders::female)) & (int(pkm->species) != int(Species::torchic)) & (int(pkm->species) != int(Species::buizel)) & (int(pkm->species) != int(Species::floatzel)))
    {
        tgender = "female";
    }
    else
    {
        tgender = "male";
    }
    o << "SELECT image FROM front_" << tgender << "_" << tshiny << "_sprites WHERE (identifier = '" << formid << "')";
}