示例#1
0
void MainWindow::onLoad()
{
    ui->detEdit->clear();
    ui->detEdit->clear();
    ui->LLEdit->clear();
    ui->normaEdit->clear();
    ui->inputEdit->clear();
    ui->solEdit->clear();

    if(A != 0) {
        for(int i = 0; i < n; i++) {
            free(A[i]);
        }
        free(A);
        A = 0;
    }
    if(d != 0) {
        free(d);
        d = 0;
    }
    if(b != 0) {
        free(b);
        b = 0;
    }

    QFile file(ui->fileNameEdit->text());
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        return;
    }

    n = file.readLine().split('\n').at(0).toInt(0, 10);
    m = file.readLine().split('\n').at(0).toInt(0, 10);

    A = (double**) malloc (n * sizeof(double*));
    d = (double*)  malloc (n * (sizeof (double)));
    b = (double*)  malloc (n * (sizeof (double)));
    x = (double*) malloc (n * sizeof(double));


    for(int i = 0; i < n; i++) {
        A[i] = (double*)  malloc (n * (sizeof (double)));
        QList<QByteArray> numbers = file.readLine().split(' ');
        for(int j = 0; j < n; j++) {
            A[i][j] = numbers.at(j).split('\n').at(0).toDouble();
        }
        d[i] = A[i][i];
    }

    QList<QByteArray> numbers = file.readLine().split(' ');
    for(int j = 0; j < n; j++) {
        b[j] = numbers.at(j).split('\n').at(0).toDouble();
    }

    printInput();
    calcDesc();
    calcDet();
    calcSol();
    calcNorma();
}
示例#2
0
文件: recursive.c 项目: younghon/quiz
int main(void)
{
	char input_arr[] = {'c','f','j','p','v','y'};
    	char key[] = {'a','c','j','s','z'};
	int inputlen = sizeof(input_arr)/sizeof(input_arr[0]);
	int keylen = sizeof(key)/sizeof(key[0]);
	int i=0;
	for(i=0;i<keylen;i++){
		printInput(input_arr, key[i]);
		printf("Output: %c\n\n",smallest_character(input_arr, key[i],inputlen));
	}
	return 0;
}
示例#3
0
int main() {
  // Print a preamble with copyright and class declaration, followed by the
  // input FP16 array, and reference outputs for pair-wise arithmetic
  // operations.
  printf("%s", preamble);
  printInput();

  printReferenceOutput(OUTPUT_ARRAY_ADD, add, 1);
  printReferenceOutput(OUTPUT_ARRAY_SUB, subtract, 1);
  printReferenceOutput(OUTPUT_ARRAY_MUL, multiply, 1);
  printReferenceOutput(OUTPUT_ARRAY_DIV, divide, 3);

  printf("}");
}
示例#4
0
文件: pm_0.c 项目: skarekroe/pm_0
int main()
{
	int input;
	FILE *file = getFile();
	FILE *out = fopen("stacktrace.txt", "w");
	code = malloc(sizeof(Instruction)*MAX_CODE_LENGTH);
	stack = calloc(MAX_STACK_HEIGHT, sizeof(int));
	int size = 0;
	//size will be calculated as each line is read in and printed out
	size = printInput(file, out, size);
	fetch(size, out);
	//execute cycle is called inside of fetch()

	fclose(file);
	fclose(out);
	return 0;
}
void process_cli(int connectfd, struct sockaddr_in client)
{
    struct headTail *headtail = malloc(sizeof(struct headTail));
    pthread_setspecific(key_headtail, headtail);
    char buffer[MAXBUF];
    int receivedBytes = -2;

    printf("You got a connection from client,IP is %s, PORT is %d\n",
                 inet_ntoa(client.sin_addr), ntohs(client.sin_port));

    /*receive the name of client*/
    receivedBytes = recv(connectfd, buffer, MAXBUF, 0);
    if(-1 == receivedBytes)
    {
        perror("receive data of name of client error");
    }
    else if (0 == receivedBytes)
    {
        printf("network disconnected accidentally.\n");
    }
    else
    {
        buffer[receivedBytes] = '\0';
        printf("The name of client is %s.\n", buffer);
        if (insert(headtail, buffer))
        {
            printf("insert name failed.\n");
        }
        else
        {
            /*recieve data*/
            while(1)
            {
                receivedBytes = recv(connectfd, buffer, MAXBUF, 0);
                if(-1 == receivedBytes)
                {
                    perror("receive data error");
                    break;
                }
                else if (0 == receivedBytes)
                {
                    /*printf("network disconnected accidentally.\n");*/
                    break;
                }

                buffer[receivedBytes] = '\0';

                if (insert(headtail, buffer))
                {
                    printf("insert failed.\n");
                    break;
                }

                reverse(buffer, receivedBytes);
                /*send data*/
                send(connectfd, buffer, strlen(buffer), 0);

            }
        }

    }
    printInput();
    close(connectfd);
    printf("[info]:close:%s.\n", inet_ntoa(client.sin_addr));
}
示例#6
0
int main(int argc, char **argv)
{
    if (argc != 3 && argc != 4)
    {
        std::cout << "Usage: Maxit_tester <program1> <program2> [<seed>]\n";
        return 1;
    }
    const char *program1 = argv[1];
    const char *program2 = argv[2];

    // init field
    if (argc >= 4)
        srand(atoi(argv[3]));
    else
        srand((unsigned int)time(NULL));
    for (int i = 0 ; i < size ; ++i)
    {
        for (int j = 0 ; j < size ; ++j)
        {
            field[i][j] = rand() % size + 1;
        }
    }
    col = 1;
    row = 1;

    // save field and score before the first move
    saveField(1);

    bool first = true;
    ExecutionResult result = ER_OK;
    for (int move = 0 ; move < size * size ; ++move)
    {
        std::ostringstream outs;
        for (int i = 0 ; i < size ; ++i)
        {
            for (int j = 0 ; j < size ; ++j)
            {
                outs << field[i][j] << " ";
            }
            outs << "\n";
        }
		outs << !first + 1 << "\n" << (first ? row : col) << "\n"; 
        std::string output;
        printInput(first, outs.str());
        result = runProcess(first ? program1 : program2, 
            outs.str(), output, 1000, 64000);
        if (result == ER_OK)
        {
            InStream ins(output);

            int rowcol;
            try
            {
                ins >> ValueInBounds<int>(rowcol, 1, size);
            }
            catch (ReadCheckerException &exception)
            {
                result = ER_IM;

                std::ostringstream outs;
                outs << output << std::endl << exception.getReadResultText() << ": " << exception.what() << std::endl;

                printLog(first, result, outs.str());
                break;
            }

            if  (
                    (first && field[row-1][rowcol-1]) ||
                    (!first && field[rowcol-1][col-1])
                )
            {

                if (first)
                    col = rowcol;
                else
                    row = rowcol;

                printLog(first, result, output);

                scores[!first] += field[row-1][col-1];
                
                field[row-1][col-1] = -field[row-1][col-1];
                // save field and score after the correct move
                saveField(!first + 1);
                field[row-1][col-1] = 0;

                // get next player
                bool canFirst = checkFirst(row);
                bool canSecond = checkSecond(col);
                if ((first && canSecond)
                    || (!first && canFirst))
                    first = !first;
                else if (canFirst)
                    first = true;
                else if (canSecond)
                    first = false;
                else 
                    break;
            }
            else
            {
                result = ER_IM;
                printLog(first, result, output);
                break;
            }
        }
        else
        {