Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    char command, parameters[MAXFILENAME+3];
    FILE *file;

    /* Initialize the limits. */
    cleanLimits();
    if (argc == 2) {
        file = fopen(argv[1], "r");
        readFile(file);
        fclose(file);
        strcpy(fileToWrite, argv[1]);
    }

    do {
        command = getchar();
        /* trailing space, \n, \0 */
        fgets(parameters, MAXFILENAME+3, stdin);
        switch(command) {
            case 'a':
                addElement(parameters);
                break;
            case 'p':
                listRelevant();
                break;
            case 'i':
                printMatrixInfo();
                break;
            case 'l':
                printLine(parameters);
                break;
            case 'c':
                printColumn(parameters);
                break;
            case 'o':
                sortElements(parameters);
                break;
            case 'z':
                changeZero(parameters);
                break;
            case 's':
                compressMatrix();
                break;
            case 'w':
                writeToFile(parameters);
                break;
        }
    } while (command != 'q');
    
    return 0;
}
Exemplo n.º 2
0
void HtmlRenderer::printTimeSeries(Response& response, ResponseStream& stream, bool noContent)
{
    Replacement rep;

    m_reps.push_back(rep);
    printTime(m_reps.back());
    if (!m_reps.back().m_found) m_reps.pop_back();

    for (size_t col=0; col < m_iter->columnsCount(); col++) {
        m_reps.push_back(rep);
        printColumn(col, m_reps.back());
        if (!m_reps.back().m_found) m_reps.pop_back();
    }

    streamContent(stream);
}
Exemplo n.º 3
0
void bt(int i)
{
  if (i > N) {
    answer++;
    if (answer <= 3) {
      printColumn();
    }
    return;
  }
  for (int j=1; j<=N; j++) {
    if (A[0][j] || A[1][N+i-j] || A[2][i+j]) continue;
    A[0][j] = A[1][N+i-j] = A[2][i+j] = 1;
    column[i] = j;
    bt(i+1);
    A[0][j] = A[1][N+i-j] = A[2][i+j] = 0;
  }
}
Exemplo n.º 4
0
void MapView::printCountries(vector<Country*> countries, int start, int end)
{
	int leftPadding = 10;
	int columnWidth = 12;

	//Print the upper part of the box frame.
	printColumn(218, 194, 196, 191, end - start, columnWidth, leftPadding);

	int maxNumAdjacentCountries = 0;

	//Calculate the maximum number of adjacent countries out of all the countries in this row.
	for (int i = start; i < end; i++)
	{
		if (countries[i]->getConnectedCountries()->size() > maxNumAdjacentCountries)
		{
			maxNumAdjacentCountries = (int)countries[i]->getConnectedCountries()->size();
		}
	}


	for (int j = 0; j < 4 + maxNumAdjacentCountries; j++)
	{
		if (editorMode && j > 1 && j < 4)
		{
			continue; //Don't show all the information if in the map editor.
		}

		switch(j)
		{
			case 0:
				cout << right << setw(leftPadding) << "Country";
				break;
			case 1:
				cout << right << setw(leftPadding) << "Continent";
				break;
			case 2:
				cout << right << setw(leftPadding) << "Owner";
				break;
			case 3:
				cout << right << setw(leftPadding) << "Armies";
				break;
			case 4:
				cout << right << setw(leftPadding) << "Adjecent";
				break;
			case 5:
				cout << right << setw(leftPadding) << "Countries";
				break;
			default:
				cout << right << setw(leftPadding) << std::string(leftPadding, ' ');
		}

		cout << char(179);

		for (int i = start; i < end; i++)
		{
			switch (j)
			{
			case 0:
				cout << left << setw(columnWidth) << truncateChar(countries[i]->getName().c_str(), columnWidth) << char(179); //Country name.
				break;
			case 1:
				cout << left << setw(columnWidth) << truncateChar(countries[i]->getContinent()->getName().c_str(), columnWidth) << char(179); //Continent name.
				break;
			case 2:
				cout << left << setw(columnWidth) << countries[i]->getControllingPlayer()->GetPlayerName(columnWidth) << char(179); //Owner of the country.
				break;
			case 3:
				cout << left << setw(columnWidth) << countries[i]->getNumArmies() << char(179); //Number of armies.
				break;
			}

			if (j > 3)
			{
				if ((j - 4) < countries[i]->getConnectedCountries()->size())
				{
					cout << left << setw(columnWidth) << truncateChar((*(countries[i]->getConnectedCountries()))[j - 4]->getName().c_str(), columnWidth) << char(179); //Adjacent countries
				}
				else
				{
					//Print empty space if the country has no more adjacent countries to print out.
					cout << left << setw(columnWidth) << std::string(columnWidth, ' ') << char(179);
				}
				
			}
		}

		cout << endl;

		if (j < 4) //Not between adjacent countries.
		{
			//Print a box section between rows.
			printColumn(195, 197, 196, 180, end - start, columnWidth, leftPadding);
		}
	}

	//Print the lower part of the box frame.
	printColumn(192, 193, 196, 217, end - start, columnWidth, leftPadding);
	
}