示例#1
0
文件: noX.cpp 项目: Sabastorm/Strings
void nox(char z[], int i) {
	if (z[i] == 0) {
		return;
	}
	if (z[i] == 'x') {
		shiftLeft(z, i);
		nox(z, i);
	} else {
		nox(z, i+1);
	}
}
示例#2
0
文件: noX.cpp 项目: Sabastorm/Strings
int main(void) {
	char s[10+1];
	scanf("%s", s);
	nox(s, 0);
	printf("%s\n", s);
	return EXIT_SUCCESS;
}
//recreate plots
void MainWindow::on_ploting_clicked()
{
    int offSet;
    QVector <double> nox(0); //x axis
    QVector<double>biggestGraphValue; //highest peak serie
    //arrays containing the color for gaps and no gaps
    vector<int>colorGap;
    vector<int>colorNoGap;
    QColor Color;
    //qvectors for the values (series)
    QVector<double> GraphValuesLeftGapQVector[20];
    QVector<double> GraphValuesLeftNoGapQVector[20];
    QVector<double> GraphValuesRightGapQVector[20];
    QVector<double> GraphValuesRightNoGapQVector[20];
    //reading the charts from gui and cleaning
    RightGap=ui->RightGap;
    LeftGap =ui->LeftGap;
    RightNoGap=ui->RightNoGap;
    LeftNoGap=ui->LeftNoGap;
    RightNoGap->clearGraphs();
    RightGap->clearGraphs();
    LeftGap->clearGraphs();
    LeftNoGap->clearGraphs();
    RightNoGap-> replot();
    RightGap-> replot();
    LeftGap-> replot();
    LeftNoGap-> replot();
    //open file
    ifstream data_file;
    string path=ui->plotPath->text().toStdString();
    data_file.open(path.c_str());
    string temp;
    if(data_file.fail())
        ui->problems->setText("fail open");
    int a=0;


    while(data_file >> temp){
        vector<string> arr;

        size_t pos = 0;
        string token;
        //read lines separing by commas until first item of the line is an integer
        while ((pos = temp.find(",")) != std::string::npos) {
            token = temp.substr(0, pos);

            arr.push_back(token);
            temp.erase(0, pos + 1);
        }

        string s=arr[0];

        QString line=s.c_str();
        int k=line.toInt();
        //if is integer read that number of lines to put the values in vectors and add to graph but first add the biggest value
        //first iteration highest peak, the last iteration of each is avg
        if(k){
            a++;
            for(int i=0;i<k;i++){
                data_file>>temp;
                vector<string> arr2;

                pos = 0;
                while ((pos = temp.find(",")) != std::string::npos) {
                    token = temp.substr(0, pos);

                    arr2.push_back(token);
                    temp.erase(0, pos + 1);
                }

                if(a==1&&i==0){
                    for(int j=0;j<arr2.size();j++){
                        nox.append(j);
                    }
                }

                if(a==1){
                    for(int j=1;j<arr2.size();j++){
                        string otherTemp=arr2[j];
                        QString otherTemp2=otherTemp.c_str();
                        biggestGraphValue.push_back(otherTemp2.toDouble());
                    }

                }
                if(a==2){


                    if(i<k-1)
                        colorNoGap.push_back(stod(arr2[0]));
                    for(int j=1;j<arr2.size();j++){
                        string otherTemp=arr2[j];
                        QString otherTemp2=otherTemp.c_str();
                        GraphValuesLeftNoGapQVector[i].push_back(otherTemp2.toDouble());


                    }

                    Color.setRgb(rand() % 100 + 100,rand() % 100 + 100,rand() % 100 + 100);

                    if(i==k-1)
                        Color.setRgb(0,0,0);
                    if(i==0){
                        LeftNoGap->addGraph();
                        LeftNoGap->graph(0)->setPen(colores[colorNoGap[i]]);
                        LeftNoGap->graph(0)->setData(nox,biggestGraphValue);
                        LeftNoGap->graph(0)->rescaleAxes();
                        LeftNoGap->graph(i)->setData(nox, GraphValuesLeftNoGapQVector[i]);
                        LeftNoGap->graph(i)->rescaleAxes(true);

                    }
                    if(i!=k-1&&i>0){
                        LeftNoGap->addGraph();
                        LeftNoGap->graph(i)->setPen(colores[colorNoGap[i]]);
                        LeftNoGap->graph(i)->setData(nox, GraphValuesLeftNoGapQVector[i]);
                        LeftNoGap->graph(i)->rescaleAxes(true);
                    }
                    if(i==k-1){
                        LeftNoGap->addGraph();
                        QPen pen;
                        pen.setColor(Color);
                        pen.setWidth(3);
                        LeftNoGap->graph(i)->setPen(pen);
                        LeftNoGap->graph(i)->setData(nox, GraphValuesLeftNoGapQVector[i]);
                        LeftNoGap->graph(i)->rescaleAxes(true);}





                }

                if(a==3){

                    for(int j=1;j<arr2.size();j++){

                        string otherTemp=arr2[j];
                        QString otherTemp2=otherTemp.c_str();
                        GraphValuesRightNoGapQVector[i].push_back(otherTemp2.toDouble());
                    }

                    Color.setRgb(rand() % 100 + 100,rand() % 100 + 100,rand() % 100 + 100);


                    if(i==k-1)
                        Color.setRgb(0,0,0);
                    if(i==0){
                        RightNoGap->addGraph();
                        RightNoGap->graph(0)->setPen(colores[colorNoGap[i]]);
                        RightNoGap->graph(0)->setData(nox,biggestGraphValue);
                        RightNoGap->graph(0)->rescaleAxes();
                        RightNoGap->graph(i)->setData(nox, GraphValuesRightNoGapQVector[i]);
                        RightNoGap->graph(i)->rescaleAxes(true);

                    }
                    if(i!=k-1&&i>0){
                        RightNoGap->addGraph();
                        RightNoGap->graph(i)->setPen(colores[colorNoGap[i]]);
                        RightNoGap->graph(i)->setData(nox, GraphValuesRightNoGapQVector[i]);
                        RightNoGap->graph(i)->rescaleAxes(true);
                    }
                    if(i==k-1){
                        RightNoGap->addGraph();
                        QPen pen;
                        pen.setColor(Color);
                        pen.setWidth(3);
                        RightNoGap->graph(i)->setPen(pen);
                        RightNoGap->graph(i)->setData(nox, GraphValuesRightNoGapQVector[i]);
                        RightNoGap->graph(i)->rescaleAxes(true);}

                }
                if(a==4){

                    if(i<k-1)
                        colorGap.push_back(stod(arr2[0]));
                    for(int j=1;j<arr2.size();j++){
                        string otherTemp=arr2[j];
                        QString otherTemp2=otherTemp.c_str();
                        GraphValuesLeftGapQVector[i].push_back(otherTemp2.toDouble());
                    }
                    Color.setRgb(rand() % 100 + 100,rand() % 100 + 100,rand() % 100 + 100);

                    if(i==k-1)
                        Color.setRgb(0,0,0);
                    if(i==0){
                        LeftGap->addGraph();
                        LeftGap->graph(0)->setPen(colores[colorGap[i]]);
                        LeftGap->graph(0)->setData(nox,biggestGraphValue);
                        LeftGap->graph(0)->rescaleAxes();
                        LeftGap->graph(i)->setData(nox, GraphValuesLeftGapQVector[i]);
                        LeftGap->graph(i)->rescaleAxes(true);

                    }
                    if(i!=k-1&&i>0){
                        LeftGap->addGraph();
                        LeftGap->graph(i)->setPen(colores[colorGap[i]]);
                        LeftGap->graph(i)->setData(nox, GraphValuesLeftGapQVector[i]);
                        LeftGap->graph(i)->rescaleAxes(true);
                    }
                    if(i==k-1){
                        LeftGap->addGraph();
                        QPen pen;
                        pen.setColor(Color);
                        pen.setWidth(3);
                        LeftGap->graph(i)->setPen(pen);
                        LeftGap->graph(i)->setData(nox, GraphValuesLeftGapQVector[i]);
                        LeftGap->graph(i)->rescaleAxes(true);}

                }
                if(a==5){
                    for(int j=1;j<arr2.size();j++){
                        string otherTemp=arr2[j];
                        QString otherTemp2=otherTemp.c_str();
                        GraphValuesRightGapQVector[i].push_back(otherTemp2.toDouble());
                    }
                    Color.setRgb(rand() % 100 + 100,rand() % 100 + 100,rand() % 100 + 100);

                    if(i==k-1)
                        Color.setRgb(0,0,0);
                    if(i==0){
                        RightGap->addGraph();
                        RightGap->graph(0)->setPen(colores[colorGap[i]]);
                        RightGap->graph(0)->setData(nox,biggestGraphValue);
                        RightGap->graph(0)->rescaleAxes();
                        RightGap->graph(i)->setData(nox, GraphValuesRightGapQVector[i]);
                        RightGap->graph(i)->rescaleAxes(true);

                    }
                    if(i!=k-1&&i>0){
                        RightGap->addGraph();
                        RightGap->graph(i)->setPen(colores[colorGap[i]]);
                        RightGap->graph(i)->setData(nox, GraphValuesRightGapQVector[i]);
                        RightGap->graph(i)->rescaleAxes(true);
                    }
                    if(i==k-1){
                        RightGap->addGraph();
                        QPen pen;
                        pen.setColor(Color);
                        pen.setWidth(3);
                        RightGap->graph(i)->setPen(pen);
                        RightGap->graph(i)->setData(nox, GraphValuesRightGapQVector[i]);
                        RightGap->graph(i)->rescaleAxes(true);}
                }

            }

        }
    }
    //replot
    LeftNoGap->xAxis2->setVisible(true);
    LeftNoGap->xAxis2->setTickLabels(false);
    LeftNoGap->yAxis2->setVisible(true);
    LeftNoGap->yAxis2->setTickLabels(false);
    LeftNoGap->replot();
    LeftGap->xAxis2->setVisible(true);
    LeftGap->xAxis2->setTickLabels(false);
    LeftGap->yAxis2->setVisible(true);
    LeftGap->yAxis2->setTickLabels(false);
    LeftGap->replot();
    RightNoGap->xAxis2->setVisible(true);
    RightNoGap->xAxis2->setTickLabels(false);
    RightNoGap->yAxis2->setVisible(true);
    RightNoGap->yAxis2->setTickLabels(false);
    RightNoGap->replot();
    RightGap->xAxis2->setVisible(true);
    RightGap->xAxis2->setTickLabels(false);
    RightGap->yAxis2->setVisible(true);
    RightGap->yAxis2->setTickLabels(false);
    RightGap->replot();


    data_file.close();

}