コード例 #1
0
ファイル: main.cpp プロジェクト: nick0lay/cpp_craft_1013
int main( int argc, char** argv ) {
    std::cout << "*homework 13*" << std::endl;

    std::ifstream inputFile( SOURCE_DIR "/sources/13/input.txt" );
    std::ofstream outputFile( SOURCE_DIR "/sources/13/output.txt" );

    if ( !inputFile.is_open() || !outputFile.is_open()) {
        std::cout << "cannot open files" << std::endl;
        return 1;
    }

    std::string line;
    std::string mainString;

    //process first line
    std::getline( inputFile, mainString );
    prepareString(mainString);

    //process keys
    while ( std::getline( inputFile, line ) ) {
        prepareString(line);
        std::reverse(line.begin(), line.end());

        if ( mainString.find(line) != std::string::npos ) {
            outputFile << "YES" << std::endl;
        } else {
            outputFile << "NO" << std::endl;
        }
    }

    inputFile.close();
    outputFile.close();

    return 0;
}
コード例 #2
0
ファイル: CEGUIFont_FreeType.cpp プロジェクト: gitrider/wxsj2
/*************************************************************************
	Recreate font glyph data map and imageset.
*************************************************************************/
void Font_FreeType::resetFontFaces(void)
{
	if(d_impldat->fontFace == 0) return;

	uint horzDpi = System::getSingleton().getRenderer()->getHorzScreenDPI();
	uint vertDpi = System::getSingleton().getRenderer()->getVertScreenDPI();

	if (d_autoScale)
	{
		horzDpi = (uint)(((float)horzDpi) * d_horzScaling);
		vertDpi = (uint)(((float)vertDpi) * d_vertScaling);
	}

	if (FT_Set_Char_Size(d_impldat->fontFace, 0, d_ptSize * 64, horzDpi, vertDpi) != 0)
	{
		// failed to set size for font
		throw GenericException((utf8*)"Font_FreeType::createFontFromFT_Face - An error occurred while creating a source font with the requested size.");
	}

	// clear font faces and memory
	clearAllFontFaces();

	//insert default data to set font size data
	prepareString((utf8*)DefaultPrepareString);

	d_lineHeight = (float)d_maxGlyphHeight;

	// calculate spacing and base-line
    d_max_bearingY = ((float)d_impldat->fontFace->ascender / (float)d_impldat->fontFace->units_per_EM) * (float)d_impldat->fontFace->size->metrics.y_ppem;
	d_lineSpacing = ((float)d_impldat->fontFace->height / (float)d_impldat->fontFace->units_per_EM) * (float)d_impldat->fontFace->size->metrics.y_ppem;
}
コード例 #3
0
void Sparse6Writer::doIO()
{
    IntegerMatrix integerMatrix = _graphPointer->getIntegerMatrix();
    // need the undirectedVersion
    integerMatrix.toUndirected();
    vector<pair<unsigned, unsigned> > groups = constructGroups(integerMatrix);

    unsigned numberOfNodes = integerMatrix.getNumberOfNodes();
    unsigned k = ceil(log2(numberOfNodes - 1));

    BitVector bitVector = constructBitvector(groups, k);

    bool last = false;
    bool beforeLast = false;

    if (numberOfNodes >= 2)
    {
        last = integerMatrix.nodeHasEdge(numberOfNodes - 1);
        beforeLast =  integerMatrix.nodeHasEdge(numberOfNodes - 2);
    }
    padUp(bitVector, numberOfNodes, k, last, beforeLast);

    string encodedGraph =  prepareString(bitVector, numberOfNodes);

    // open a filestream
    fstream fileStream(_fileName.c_str(), ios::out);
    // the format is defined so that after the header there is no linebreak
    fileStream << _header << ":"; // need the ':' character to identify s6 format
    fileStream << encodedGraph;
    fileStream.close();
}
コード例 #4
0
KJFileInfo::KJFileInfo(const QStringList &l, KJLoader *p)
	: KJWidget(p), mBack(0)
{
	mInfoType = l[0]; // type of info-display

	int x  = l[1].toInt();
	int y  = l[2].toInt();
	int xs = l[3].toInt() - x;
	int ys = l[4].toInt() - y;

	// fix for all those weird skins where the timewindow
	// has more space than needed for the font
	int maxNeededHeight = timeFont().fontHeight();
	if ( ys > maxNeededHeight )
		ys = maxNeededHeight;

	// five digits + spacing between them
	int maxNeededWidth = ( 3 *timeFont().fontWidth() ) + ( 2 * timeFont().fontSpacing() );
	if ( xs > maxNeededWidth )
		xs = maxNeededWidth;

	// background under info-display
	QPixmap tmp  = p->pixmap(p->item("backgroundimage")[1]);
	mBack = new KPixmap ( QSize(xs,ys) );
	bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, Qt::CopyROP );

	setRect(x,y,xs,ys);

	prepareString("");
}
コード例 #5
0
KJPitchText::KJPitchText(const QStringList &l, KJLoader *p)
	: KJWidget(p), mBack(0)
{
	int x  = l[1].toInt();
	int y  = l[2].toInt();
	int xs = l[3].toInt() - x;
	int ys = l[4].toInt() - y;

	// fix for all those weird skins where the timewindow has more space than needed for the font
	if ( ys > (pitchFont().fontHeight()) )
		ys = pitchFont().fontHeight();

	// 3 digits for volume (1-100), spaces according to spacing and percentage letter
	int tempWidth = (3*pitchFont().fontWidth()) + (2*pitchFont().fontSpacing());
	if ( xs > tempWidth )
		xs = tempWidth;

	// background under time-display
	QPixmap tmp  = p->pixmap(p->item("backgroundimage")[1]);
	mBack = new KPixmap ( QSize(xs,ys) );
	bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, Qt::CopyROP );

	setRect(x,y,xs,ys);

	prepareString("100");
}
コード例 #6
0
KJFilename::KJFilename(const QStringList &l, KJLoader *p)
	: QObject(0), KJWidget(p), mBack(0)
{
	int x  = l[1].toInt();
	int y  = l[2].toInt();
	int xs = l[3].toInt() - x;
	int ys = l[4].toInt() - y;

	// fix for all those weird skins where the filenamewindow has more
	// height than needed for the font
	// ( ... usually resulting in garbage on-screen )
	if ( ys > (textFont().fontHeight()) )
		ys = textFont().fontHeight();

	// background under filename-scroller
	QPixmap tmp  = p->pixmap(p->item("backgroundimage")[1]);
	mBack = new KPixmap ( QSize(xs,ys) );
	bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, Qt::CopyROP );

	setRect(x,y,xs,ys);

	// how far it moves per cycle
	// TODO: make that configurable for the user

	//mDistance = 1;
//	mDistance = (int)(textFont().fontWidth()/2);
	readConfig();

	prepareString(i18n("Welcome to Noatun").local8Bit());
	killTimers();
}
コード例 #7
0
KJVolumeText::KJVolumeText(const QStringList &l, KJLoader *p)
	: KJWidget(p), mBack(0)
{
	int x=l[1].toInt();
	int y=l[2].toInt();
	int xs=l[3].toInt()-x;
	int ys=l[4].toInt()-y;

	// fix for all those weird skins where the timewindow has more space than needed for the font
	if ( ys > (volumeFont().fontHeight()) )
		ys = volumeFont().fontHeight();

	// 3 digits for volume (1-100)
	// + spaces according to spacing
	// + percentage letter (seems to be 1px wider than a normal char)
	int tempWidth = (3*volumeFont().fontWidth()) + (2*volumeFont().fontSpacing()) + ((volumeFont().fontWidth()+1));
	if ( xs > ( tempWidth ) )
		xs = tempWidth;

	// background under volumetext-display
	QPixmap tmp  = p->pixmap(p->item("backgroundimage")[1]);
	mBack = new KPixmap ( QSize(xs,ys) );
	bitBlt( mBack, 0, 0, &tmp, x, y, xs, ys, Qt::CopyROP );

	setRect(x,y,xs,ys);

	prepareString("100%");
}
コード例 #8
0
void KJTime::timeUpdate(int)
{
//	kdDebug(66666) << "START KJTime::timeUpdate(int)" << endl;
	if (!napp->player()->current())
		return;

	prepareString( (lengthString()).latin1() );

//	kdDebug(66666) << "END KJTime::timeUpdate(int)" << endl;
}
コード例 #9
0
void KJVolumeText::timeUpdate(int)
{
	QCString volume;

	if (!napp->player()->current())
		return;

	volume.sprintf("%d%%", napp->player()->volume() ); // FIXME: is sprintf safe to use?

	prepareString(volume);
}
コード例 #10
0
void KJPitchText::timeUpdate(int)
{
	QCString speed;

	if (!napp->player()->current())
		return;

	Arts::PlayObject playobject = napp->player()->engine()->playObject();
	Arts::PitchablePlayObject pitchable = Arts::DynamicCast(playobject);

	if (pitchable.isNull())
		return;

	speed.setNum ( (int) ((float)pitchable.speed()*(float)100) );
	prepareString ( speed );
}
コード例 #11
0
void KJFilename::timeUpdate(int)
{
	if ( !napp->player()->current() ) // just for safety
		return;

	QCString title = QCString( napp->player()->current().title().local8Bit() );

	if ( title == mLastTitle )
		return;

	mLastTitle = title;

	QCString timestring = napp->player()->lengthString().local8Bit();
	timestring = timestring.mid(timestring.find('/')+1);
	prepareString ( title + " (" + timestring + ")   ");
}
コード例 #12
0
void KJFileInfo::timeUpdate(int)
{
	if (!napp->player()->current())
		return;

	const PlaylistItem &item = napp->player()->current();
	QString prop;

	if ( mInfoType == "mp3khzwindow" )
	{
		prop = item.property("samplerate");
		prop.truncate(2); // we just want 44 instead of 44100
	}
	else if ( mInfoType == "mp3kbpswindow" )
	{
		prop = item.property("bitrate");
	}
	else	// for safety: no infoType we know of
		return;

	if (prop.isNull())
		prop="";
	prepareString( prop.latin1() );
}
コード例 #13
0
ファイル: PCalc.cpp プロジェクト: petrpopov/db_transactions
QString PCalc::convertString(const QString &string)
{
	QString rStr = prepareString(string);
	QString cStr = "";
	QStack<QChar> stack;

	QStringList rList = rStr.split(" ");
	for(int i = 0; i < rList.count(); i++)
	{
		bool ok = false;
		double d = rList[i].toDouble(&ok);
		if(ok)
			cStr += rList[i] += " ";
		else
		{
			if(rList[i] == "(")
			{
				QChar c = rList[i].at(0);
				stack.push(c);
			}
			else if(rList[i] == "+" || rList[i] == "-" || rList[i] == "*" || rList[i] == "/" || rList[i] == "^")
			{
				bool ex = false;
				QChar c = rList[i].at(0);
				if(!stack.isEmpty())
				{
					if( getPriority(stack.top()) >= getPriority(c) )
						ex = true;
					while(ex)
					{
						QChar p = stack.pop();
						cStr += p;
						cStr += " ";

						if( getPriority(stack.top()) < getPriority(c) )
							ex = false;
						if( stack.isEmpty() )
							ex = false;
					}
				}
				
				stack.push( c );
			}
			else if(rList[i] == ")")
			{
				bool ex = false;
				while(!ex)
				{
					if(stack.isEmpty())
					{
						ex = true;
						continue;
					}
					QChar c = stack.pop();
					if(c != '('){
						cStr += c;
						cStr += " ";
					}
					else
						ex = true;
				}
			}
		}
	}
	while(!stack.isEmpty())
	{
		cStr += stack.pop();
		cStr += " ";
	}
	cStr = cStr.trimmed();

	return cStr;
}
コード例 #14
0
static int splitUnicodeString(Splitter *self,PyUnicodeObject *doc)
{

    PyObject *word,*synword;
    PyUnicodeObject * doc1;
    Py_UNICODE *s;

    int len = doc->length;
    int inside_word=0;
    int i=0;
    int start=0;

    doc1 = prepareString(self,doc);
    if (doc1 == NULL)
      return -1;

    s=doc1->str;

    self->list = PyList_New(0);

    for (i = 0; i < len; s++, i++) {
        register Py_UNICODE ch;

        ch = *s;

        if (!inside_word) {
            if (self->index_numbers) {
                if (Py_UNICODE_ISALNUM(ch)) {
                    inside_word=1;
                    start = i;
                }

            } else {
                if (Py_UNICODE_ISALPHA(ch)) {
                    inside_word=1;
                    start = i;
                }
            }
        } else {

            if (!(Py_UNICODE_ISALNUM(ch) || ch=='/' || ch=='_' || ch=='-')) {
                inside_word = 0;

                word = PySequence_GetSlice((PyObject *)doc1,start,
                                           min(i, start + self->max_len));
                if (word==NULL)
                  goto err;

                synword = checkSynword(self,word);
                if (synword != Py_None) {
                  PyList_Append(self->list,synword);
                }

                start =  0;
#ifdef DEBUG
                PyObject_Print(word,stdout,0);
                fflush(stdout);
#endif
                Py_DECREF(word);
            }
        }
    }

    if (inside_word) {
        word = PySequence_GetSlice((PyObject *)doc1,start,
                                   min(len, start + self->max_len));
        if (word==NULL)
          goto err;

        synword = checkSynword(self,word);
        if (synword != Py_None) {
          PyList_Append(self->list,synword);
        }

        Py_DECREF(word);
    }

#ifdef DEBUG
    PyObject_Print(self->list,stdout,0);
    fflush(stdout);
#endif

    Py_DECREF(doc1);
    return 1;

 err:
    Py_DECREF(doc1);
    return -1;
}