int main(int argc, char *argv[]) { int num = atoi(argv[1]); int findNumber(int i) { if (i%2 == 1) { return findNumber(i-1); } else if (i == 0) { return 1; } else { return findNumber(i-1) + findNumber(i-2); } } int numerator = findNumber(num); int denominator = findNumber(num+1); printf("%d/%d\n", numerator, denominator); return 0; }
int main(int argc, char *argv[]) { int num; Matrix *m; for ( int i = 1; i < argc; i++ ) { num = findNumber( argv[i] ); if ( num == -1 ) FileNameError(); jacobi( loadMatrix( argv[i] ), num ); printf( " : finish!\n" ); } if ( argc == 1 ) { printf( "コマンドライン引数で固有値を求めたい対称行列を入力してください.(複数可)\n" "入力:\n" " ファイル名:sigmaxx.txt\n" " 中身:n*nの対称行列\n" " x.x x.x x.x ... x.x\n" " : : \n" " x.x x.x x.x ... x.x\n" "出力:\n" " ファイル名:eigenxx.txt\n" " 中身:固有値とそれに対応する固有ベクトル(λk > λk+1)\n" " λ1 v1-1 v1-2 ... v1-n\n" " : : \n" " λn vn-1 vn-2 ... vn-n\n" ); } return 0; }
int main() { int a[]={2,3,6,5,22,8,4}; int size=7; printf("%s",findNumber(a,size,8)); return 0; }
int main(int argc, char *argv[]) { int num; Matrix *m; for ( int i = 1; i < argc; i++ ) { num = findNumber( argv[i] ); if ( num == -1 ) FileNameError(); jacobi( loadMatrix( argv[i] ), num ); } return 0; }
/* ** Function: newDigit ** ** Description: ** Called whenever new pulse digit or DTMF digit is collected ** Digit is added to digit buffer and findNumber is called to search for a match ** in the 'phonebook' ** ** Input Parameters: ** pState: pointer to channel state data structure ** asciiChar: digit pressed on the phone ** ** Return: ** none */ static void newDigit (chanState *pState, uInt8 asciiChar) { pt2Func funct; funct = NULL; if (pState->digitCount < 19) { pState->digits[pState->digitCount] = asciiChar; pState->digitCount++; pState->digits[pState->digitCount]= 0; #if(PRINTF_IS_OK) printf("Value= %c String collected \"%s\" ", asciiChar, pState->digits ); #endif funct = findNumber(pState); if (funct) funct(pState); } }
bool isNumber(const char *s) { // Start typing your C/C++ solution below // DO NOT write int main() function int i = 0; while(s[i] != '\0' && s[i] == ' ') {//trim blank before string i++; } int pos = findNumber(s, i); if(pos == -1) return false; if(s[pos] == '\0') return true; else if(s[pos] == 'e') { pos = findNumberAfterE(s, pos+1); if(pos == -1) return false; else if(s[pos] == '\0') return true; else { while(s[pos] != '\0') { if(s[pos] != ' ') return false; pos++; } return true; } }else if(s[pos] == ' ') { while(s[pos] != '\0') { if(s[pos] != ' ') return false; pos++; } return true; } return false; }
bool batchUpdateForGroup(int rowNum1, int colNum1, int rowNum2, int colNum2){ // Eliminate all numbers from slot 2 in slot 1 for(int k = 1; k < 10; ++k){ if(board[rowNum2][colNum2][k] == 1 && board[rowNum1][colNum1][k] == 1){ board[rowNum1][colNum1][k] = 0; --board[rowNum1][colNum1][0]; if(board[rowNum1][colNum1][0] <= 0) return false; } } if(board[rowNum1][colNum1][0] == 1){ if(!updateBoard(rowNum1, colNum1, findNumber(rowNum1, colNum1))) return false; } return true; }
WidgetCzyPierwsza::WidgetCzyPierwsza(QWidget *parent) : QWidget(parent) { this->setWindowTitle("Sito Eratostenesa"); // Proram sie dlugo uruchamia z powodu konstruktora // w ktorej wypelnia on dosyc duza tablice. // To moze trwac nawet 10 sekund! QSito = new QSitoEratostenesa(); QLabel *label = new QLabel("Czy liczba jest pierwsza?"); label->setFont(QFont("Times", 18, QFont::Bold)); wybor = new WidgetWybor(QSito); bLabel = new QLabel("TAK"); bLabel->setFont(QFont("Times", 18, QFont::Bold)); textedit = new QTextEdit; textedit->setReadOnly(true); QPushButton *button = new QPushButton("Oblicz zakres"); QLabel *label2 = new QLabel("UWAGA! Duzy zakres moze spowolnic lub nawet zawiesic program!"); QHBoxLayout *layout2 = new QHBoxLayout; layout2->addWidget(button); layout2->addWidget(label2); connect(wybor->getLiczba(), SIGNAL(valueChanged(int)), QSito, SLOT(setCzyLiczbaPierwsza(int))); connect(QSito, SIGNAL(usedCzyLiczbaPierwsza(bool)), this, SLOT(changebLabel(bool))); connect(button, SIGNAL(clicked()), this, SLOT(changeDocument())); connect(wybor->getLiczba(), SIGNAL(valueChanged(QString)), this, SLOT(findNumber(QString))); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(label); layout->addWidget(wybor); layout->addWidget(bLabel); layout->addLayout(layout2); layout->addWidget(textedit); setLayout(layout); }
int main(int argc, char *argv[]){ if (argc != 2){ printf("Wrong number of arguments. Needed exactly one argument.\n"); return 1; } int n = atoi(argv[1]); int * mas = NULL; initArray(&mas, n); printArray(mas, n); sortArray(mas, n); printArray(mas, n); printf("%d\n", findNumber(mas, mas[n / 2 + 1], 0, n - 1)); free(mas); return 0; }
bool updateBoard(int rowNum, int colNum, int fixedNum){ // Update the board onece a new slot is fixed for(int i = 0; i < 9; ++i){ // Update current row if(i != colNum){ if(board[rowNum][i][fixedNum] == 1){ board[rowNum][i][fixedNum] = 0; --board[rowNum][i][0]; if(board[rowNum][i][0] <= 0){ return false; } if(board[rowNum][i][0] == 1){ if(!updateBoard(rowNum, i, findNumber(rowNum, i))){ return false; } } } } } for(int i = 0; i < 9; ++i){ // Update current column if(i != rowNum){ if(board[i][colNum][fixedNum] == 1){ board[i][colNum][fixedNum] = 0; --board[i][colNum][0]; if(board[i][colNum][0] <= 0){ return false; } if(board[i][colNum][0] == 1){ if(!updateBoard(i, colNum, findNumber(i, colNum))){ return false; } } } } } int rowBase, colBase; rowBase = (rowNum / 3) * 3; colBase = (colNum / 3) * 3; for(int i = 0; i < 3; ++i){ // Update current square for(int j = 0; j < 3; ++j){ if(rowBase + i != rowNum || colBase + j != colNum){ if(board[rowBase + i][colBase + j][fixedNum] == 1){ board[rowBase + i][colBase + j][fixedNum] = 0; --board[rowBase + i][colBase + j][0]; if(board[rowBase + i][colBase + j][0] <= 0){ return false; } if(board[rowBase + i][colBase + j][0] == 1){ if(!updateBoard(rowBase + i, colBase + j, findNumber(rowBase + i, colBase + j))){ return false; } } } } } } return true; }
int main () { int menuOption; contactList contactList; char name[40]; char phone_number[9]; char *email; char *mail; contactList.head=NULL; do { printf("(1) Find Contact by name\n"); printf("(2) Find Contact by phone number\n"); printf("(3) Show all contacts\n"); printf("(4) Modify Contact information\n"); printf("(5) Add contact\n"); printf("(6) Delete contact\n"); printf("(7) Load contacts from file\n"); printf("(8) Quit\n"); scanf("%d", &menuOption); fflush(stdin); switch (menuOption) { case 1: printf("Enter name: \n"); scanf(" %[^\n]s", name); findName(&contactList, name); break; case 2: printf("Enter phone number: \n"); scanf("%s", phone_number); findNumber(&contactList, phone_number); break; case 3: showAllContact(&contactList); break; case 4: printf("Enter name: \n"); scanf(" %[^\n]s", name); modifyContact(&contactList, name); break; case 5: printf("Please enter name: "); scanf(" %[^\n]s", name); printf("Please enter phone number: "); scanf(" %[^\n]s", phone_number); printf("Please enter email address: "); email = getAddress(); fflush(stdin); printf("Please enter mail address: "); mail = getAddress(); fflush(stdin); addContact(&contactList, name, phone_number, email, mail); break; case 6: printf("Enter name: \n"); scanf(" %[^\n]s", name); deleteContact(&contactList,name); break; case 7: loadFile(&contactList); break; case 8: printf("Bye Bye!"); break; } }while(menuOption != 8); return 0; }
int singleNumber(int A[], int n) { return findNumber(A, n, 3, 1); }
int main (int argc, const char * argv[]) { // choose which zero of autocorrelation should be set as delay parameter int delay_choice =2; int embed_dimension =3; int num_neighbours = 15; long num_of_points_retained=500; int percentile =70; long output_len=2*(((float)percentile)/100)*num_of_points_retained; printf("%ld output_len =",output_len); float *output = malloc(output_len* sizeof(float)); printf("Density based subsampling running \n"); if (argc != 2) { fprintf(stderr, "Expecting wav file as argument\n"); return 1; } // Open sound file that comes in as a command line argument SF_INFO sndInfo; SNDFILE *sndFile = sf_open(argv[1], SFM_READ, &sndInfo); if (sndFile == NULL) { fprintf(stderr, "Error reading source file '%s': %s\n", argv[1], sf_strerror(sndFile)); return 1; } // Check format - 16bit PCM if (sndInfo.format != (SF_FORMAT_WAV | SF_FORMAT_PCM_16)) { fprintf(stderr, "Input should be 16bit Wav\n"); sf_close(sndFile); return 1; } // Now we know the length of the wav file, we can create a buffer for it, in this case, we are creating a double array. // Allocate memory float *buffer = malloc(sndInfo.frames * sizeof(float)* sndInfo.channels); if (buffer == NULL) { fprintf(stderr, "Could not allocate memory for data\n"); sf_close(sndFile); return 1; } // This next step, actually reads in the wav file data. This function automatically converts the whichever format the audio file data is in to doubles. The library can convert to a number of different formats. // Load data long numFrames = sf_readf_float(sndFile, buffer, sndInfo.frames); // Check correct number of samples loaded if (numFrames != sndInfo.frames) { fprintf(stderr, "Did not read enough samples for source\n"); sf_close(sndFile); free(buffer); return 1; } // Now just output some info about the wav file printf("Read %ld samples from %s, Sample rate: %d, Length: %fs\n", numFrames, argv[1], sndInfo.samplerate, (float)numFrames/sndInfo.samplerate); // extract a single channel out float *buffer_singlechannel = malloc(sndInfo.frames * sizeof(float)); long i=0; for (long f=0 ; f<numFrames ; f++) { buffer_singlechannel[f]= buffer[i]; // Channel 1 i+=sndInfo.channels; } // free the buffer with multiple channel input free(buffer); // array to store the autocorrelation function double *buffer_autocorrelation = malloc((2*sndInfo.frames +1)* sizeof(double)); // calculate autocorrelation xcorr( buffer_singlechannel, buffer_singlechannel, buffer_autocorrelation, sndInfo.frames, 0,sndInfo.frames, 1, 1, sndInfo.frames,sndInfo.frames, sndInfo.frames, sndInfo.frames); // choose delay to be second zero of auto correlation long long delay = zeroCrossing(buffer_autocorrelation, 2*sndInfo.frames +1, delay_choice); printf("Delay chosen = %lld\n",delay); long long delay_embd_length= (sndInfo.frames -(delay*embed_dimension)+2)* embed_dimension; //create delay embedding and store in a linear array in row major form float *buffer_delayembedding =malloc(delay_embd_length*sizeof(float)); long long k1=0; for (long long l=(delay*embed_dimension)-2; l<sndInfo.frames; l=l+1) { buffer_delayembedding[k1]=buffer_singlechannel[l]; buffer_delayembedding[k1+1]=buffer_singlechannel[l-delay]; buffer_delayembedding[k1+2]=buffer_singlechannel[l-2*delay]; // printf("%f %f %f\n", buffer_delayembedding[k1],buffer_delayembedding[k1+1],buffer_delayembedding[k1+2]); k1=k1+embed_dimension; } int *array =malloc(num_of_points_retained *sizeof(int)); random_selector( delay_embd_length/ embed_dimension ,num_of_points_retained , array); for (int i=0; i<num_of_points_retained; i++) { // printf("%d\n",array[i]); } float *buffer_delayembedding_selec =malloc(num_of_points_retained*embed_dimension*sizeof(float)); float * density_vals =malloc(num_of_points_retained* sizeof(float)); printf("total len = %lld\n ", delay_embd_length/3 ); printf("buffer len = %ld\n", num_of_points_retained*embed_dimension); printf("num_of_points_retained = %ld\n", num_of_points_retained); for (int i=0; i<num_of_points_retained; i=i+1) { int loc=(array[i]-1)*embed_dimension; // printf("i :%d loc=%d array[i]: %d \n",i, loc, array[i]); buffer_delayembedding_selec[3*i]=buffer_delayembedding[loc]; buffer_delayembedding_selec[3*i+1]=buffer_delayembedding[loc+1]; buffer_delayembedding_selec[3*i+2]=buffer_delayembedding[loc+2]; // printf("buffer selec [%d] = %f ", 3*i, buffer_delayembedding_selec[3*i]); // printf("[%d] = %f ", 3*i+1, buffer_delayembedding_selec[3*i+1]); // printf("[%d] = %f \n", 3*i+2, buffer_delayembedding_selec[3*i+2]); } // for (int i=0; i<delay_embd_length/ embed_dimension ; i++) // { // printf("% d th original :%f %f %f\n",i, buffer_delayembedding [3*i],buffer_delayembedding [3*i+1],buffer_delayembedding [3*i+2]); // } knn (buffer_delayembedding_selec, density_vals , (num_of_points_retained), num_neighbours); // free all arrays used till now except the single channel wave file and close the sndFile object sf_close(sndFile); //desnity based subsampling float * density_vals_temp =malloc(num_of_points_retained* sizeof(float)); memcpy(density_vals_temp,density_vals,num_of_points_retained* sizeof(float)); qsort(density_vals_temp, num_of_points_retained, sizeof(float), cmpfunc); float key=findNumber(100-percentile,density_vals_temp,500); // Function call and the print statement // printf(" \n %d percentile: %.4lf \n", percentile, key); printf(" \n the linear array output contains the subsampled point cloud \n"); //for (int kk=0; kk<num_of_points_retained; kk++) { // printf("%d index %f \n", kk,density_vals_temp[kk]); //} free(density_vals_temp); int counter2=0; for( int counter = 0 ; counter < num_of_points_retained; counter++) { if (density_vals[counter]>=key && counter2<output_len/2) { output[2*counter2]=buffer_delayembedding_selec[3*counter]; output[2*counter2+1]=buffer_delayembedding_selec[3*counter+1]; //printf("%d output %.4lf , %.4lf\n", counter2,output[2*counter2],output[2*counter2+1]); //printf("%d output %.4lf , %.4lf\n", counter,buffer_delayembedding_selec[3*counter],buffer_delayembedding_selec[3*counter+1]); counter2++; } } free(buffer_singlechannel); free(buffer_autocorrelation); free(buffer_delayembedding); free(array); free(buffer_delayembedding_selec); free(density_vals); printf("Density based subsampling End\n"); free(output); return 0; }