int refreshMatrix(char* m[], kigyo** k) { #ifdef ANSI return writeMatrix (m,k); #else int i,j; for (i=0; i<Y; i++) { for (j=0; j<X; j++) { if ( mold[i][j] != m[i][j] ) { gotoxy(j+1,i+1); kiir("%c",m[i][j]); mold[i][j]=m[i][j]; } } } gotoxy(X+14,1); kiir("%3d",k[0][0].pont); if ( getMulti() ) { gotoxy(X+14,2); kiir("%3d",k[1][0].pont); } gotoxy(X+7,4); kiir("%3d",getEtel()); #ifdef LINUX refresh(); #endif return 0; #endif }
void clearStatus2() { char s[]=" "; if (!cleared1) { gotoxy(X+3,Y-1); kiir("%s",s); cleared1=1; } }
void clearStatus() { char s[]=" "; if (!cleared) { gotoxy(X+3,Y-2); kiir("%s",s); cleared=1; } }
void kiir (BINFA_PTR elem) { if (elem != NULL) { ++melyseg; if (melyseg > max_melyseg) max_melyseg = melyseg; kiir (elem->jobb_egy); // ez a postorder bejáráshoz képest // 1-el nagyobb mélység, ezért -1 for (int i = 0; i < melyseg; ++i) printf ("---"); printf ("%c(%d)\n", elem->ertek < 2 ? '0' + elem->ertek : elem->ertek, melyseg - 1); kiir (elem->bal_nulla); --melyseg; } }
int writeMatrix(char* m[], kigyo** k) { int i,j; for (i=-1; i<=Y; i++) { for (j=-1; j<=X; j++) { if (i==-1 || i == Y) kiir("%c",'-'); else if (j==-1 || j==X) kiir("%c",'|'); else kiir("%c",m[i][j]); if ( i==-1 && j==X ) kiir(" Pontszamok:"); else if ( i==0 && j == X ) kiir(" %c jatekos: %3d",k[0][0].j,k[0][0].pont); else if ( getMulti() && i==1 && j == X ) kiir(" %c jatekos: %3d",k[1][0].j,k[1][0].pont); else if ( i==3 && j == X ) kiir(" Meg %3d etel",getEtel()); if ( i>-1 && j>-1 && j<X && i < Y) { mold[i][j]=m[i][j]; } } kiir("%c",'\n'); } if ( getMulti() ) kiir("%c - iranyitas w,a,s,d BULLET TIME q\n",k[1][0].j); kiir("%c - iranyitas i,j,k,l BULLET TIME u\n",k[0][0].j); return 0; }
int main() { FILE *f=fopen("szavazatok.txt","r"); int i=0; while (!feof(f)) { fscanf(f,"%i",&t[i].kerulet); fscanf(f,"%i",&t[i].szavazat_szam); fscanf(f,"%s",t[i].jelolt[0]); fscanf(f,"%s",t[i].jelolt[1]); fscanf(f,"%s\r\n",t[i].part_nev); i+=1; } int c; for (c=0; c<i; c+=1) kiir(&t[c]); // 2. feladat printf("2. feladat:%i",i); // 3. feladat printf("Adj meg képviselõt!\r\n"); char n_vez[100]; char n_ker[100]; printf("Vezeteknev:"); scanf("%s",n_vez); printf("\r\nKeresztnev:"); scanf("%s",n_ker); printf("\r\n"); for (c=0; c<i; c+=1) { if (!strcmp(n_vez,t[c].jelolt[0])) if (!strcmp(n_ker,t[c].jelolt[1])) { printf("szavazatok szama:%i",t[c].szavazat_szam); break; } } if (c>=i) printf("Nincs"); int ossz_szavazatok_szama=0; for (c=0; c<i; c+=1) ossz_szavazatok_szama += t[c].szavazat_szam; print("ossz_szavazatok_szama:%i\r\n",ossz_szavazatok_szama); print("reszveteli arany:%.2f%%\r\n",(ossz_szavazatok_szama*100.0)/12345.0); // 5. feladat int t_partok[5]= {0,0,0,0,0}; // GYEP,HEP,TISZ,ZEP,FUG(-) for (c=0; c<i; c+=1) { if ( !strcmp(t[c].part_nev,"GYEP") ) t_partok[0]+=t[c].szavazat_szam; if ( !strcmp(t[c].part_nev,"HEP") ) t_partok[1]+=t[c].szavazat_szam; if ( !strcmp(t[c].part_nev,"TISZ") ) t_partok[2]+=t[c].szavazat_szam; if ( !strcmp(t[c].part_nev,"ZEP") ) t_partok[3]+=t[c].szavazat_szam; if ( !strcmp(t[c].part_nev,"-") ) t_partok[4]+=t[c].szavazat_szam; } printf("GYEP%.2f:",(t_partok[0]*100.0)/ossz_szavazatok_szama); printf("HEP%.2f:",(t_partok[1]*100.0)/ossz_szavazatok_szama); printf("TISZ%.2f:",(t_partok[2]*100.0)/ossz_szavazatok_szama); printf("ZEP%.2f:",(t_partok[3]*100.0)/ossz_szavazatok_szama); printf("FUG%.2f:",(t_partok[4]*100.0)/ossz_szavazatok_szama); //6. feladat int tmp; int max_szav=t[0].szavazat_szam; for (c=1; c<i; c+=1) if (max_szav < t[c].szavazat_szam) max_szav=szavazat_szam; for (c=0; c<i; c+=1) if (t[c].szavazat_szam == max_szav ) kiir(&t[c]); // 7. feladat int ker_max[8]= {0,0,0,0,0,0,0,0}; for (c=0; c<i; c+=1) if ( ker_max[ t[c].kerulet-1] < t[c].szavazat_szam ) ker_max[ t[c].kerulet-1] = t[c].szavazat_szam; /* Jó megoldás, de nem teljesíti a kerület szerinti rendezettséget for (c=0; c<i; c+=1) if ( ker_max[t[c].kerulet-1] == t[c].szavazat_szam) kiir(&t[c]); */ FILE *g=fopen("kepviselo.txt","w"); int k; for (k=1; k<=8; k+=1) for (c=0; c<i; c+=1) if ( t[c].kerulet == k) if ( ker_max[k-1] == t[c].szavazat_szam) if (!strcmp(t[c].part_nev,"-")) fprinf(g,"%i %s %s fuggetlen", k, t[c].jelolt[0],t[c].jelolt[1]); else fprinf(g,"%i %s %s %s", k, t[c].jelolt[0],t[c].jelolt[1],t[c].part_nev); fclose(g); fclose(f); getch(); return 0; }
void MainWindow::binom(){ frmSettings *dlg = new frmSettings(); QSettings settings(QSettings::IniFormat, QSettings::UserScope, "RJsoft", "ssconf"); settings.beginGroup("CIprms"); if(settings.contains("k")){ dlg->m_ui->spinBox->setValue(settings.value("k").toInt()); } else { dlg->m_ui->spinBox->setValue(0); } if(settings.contains("n")){ dlg->m_ui->spinBox_2->setValue(settings.value("n").toInt()); } else { dlg->m_ui->spinBox_2->setValue(0); } if(settings.contains("alpha")){ dlg->m_ui->doubleSpinBox_3->setValue(settings.value("alpha").toDouble()); } else { dlg->m_ui->doubleSpinBox_3->setValue(0.95); } if(settings.contains("Sp")){ dlg->m_ui->doubleSpinBox_2->setValue(settings.value("Sp").toDouble()); } else { dlg->m_ui->doubleSpinBox_2->setValue(1.0); } if(settings.contains("Se")){ dlg->m_ui->doubleSpinBox->setValue(settings.value("Se").toDouble()); } else { dlg->m_ui->doubleSpinBox->setValue(1.0); } if(settings.contains("method")){ dlg->m_ui->comboBox->setCurrentIndex(dlg->m_ui->comboBox->findText(settings.value("method").toString(), Qt::MatchExactly)); } else { dlg->m_ui->comboBox->setCurrentIndex(dlg->m_ui->comboBox->findText("Blaker", Qt::MatchExactly)); } settings.endGroup(); if (dlg->exec() == QDialog::Accepted ){ QApplication::setOverrideCursor( Qt::WaitCursor ); unsigned int k = dlg->m_ui->spinBox->value(); unsigned int n = dlg->m_ui->spinBox_2->value(); double conf = dlg->m_ui->doubleSpinBox_3->value(); double alpha = 1-conf; double Se = dlg->m_ui->doubleSpinBox->value(); double Sp = dlg->m_ui->doubleSpinBox_2->value(); settings.beginGroup("CIprms"); settings.setValue("k", k); settings.setValue("n", n); settings.setValue("alpha", dlg->m_ui->doubleSpinBox_3->value()); settings.setValue("Sp", Sp); settings.setValue("Se", Se); settings.setValue("method",dlg->m_ui->comboBox->currentText()); settings.endGroup(); double pbal = 0, pjobb=1, sum=0; double prev = (double)k/(double)n; ui->plainTextEdit->appendPlainText( QString("Number of test positives: %1 out of %2\nSensitivity: %3 Specificity: %4 Confidence level: %5 Method: %6\n") .arg(k).arg(n).arg(Se).arg(Sp).arg(conf) .arg(dlg->m_ui->comboBox->currentText()) ); if (dlg->m_ui->comboBox->currentText()=="Sterne"){ // ---------------------------------------------------------- // -------------------- S T E R N E ------------------------- // ---------------------------------------------------------- //bal int z =0; for(double p=0.0001; p<=0.9999; p = p+0.0001){ sum=0; double kp = gsl_ran_binomial_pdf(k, p, n); for(unsigned int x=0; x!=n+1; x++){ double xp = gsl_ran_binomial_pdf(x, p, n); if (xp<=kp){ sum = sum+xp; } } if (sum<alpha){ pbal = p; // ui->plainTextEdit->appendPlainText(QString("sum: %1; p: %2").arg(sum).arg(p)); } else { break; } z++; } //jobb z =0; for(double p=0.9999; p>=0.0001; p = p-0.0001){ sum=0; double kp = gsl_ran_binomial_pdf(k, p, n); for(unsigned int x=0; x!=n+1; x++){ double xp = gsl_ran_binomial_pdf(x, p, n); if (xp<=kp){ sum = sum+xp; } } if (sum<alpha){ pjobb = p; } else { break; } z++; } } else if (dlg->m_ui->comboBox->currentText()=="Blaker"){ // ---------------------------------------------------------- // -------------------- B L A K E R ------------------------- // ---------------------------------------------------------- //bal int z =0; for(double p=0.0001; p<=0.9999; p = p+0.0001){ sum=0; double kp = gsl_cdf_binomial_P(k, p, n); // ui->plainTextEdit->appendPlainText(QString("k %1 p %2 n %3 kp %4\n").arg(k).arg(p).arg(n).arg(kp)); double kp2 = gsl_cdf_binomial_Q(k, p, n) + gsl_ran_binomial_pdf(k, p, n); // ui->plainTextEdit->appendPlainText(QString("k %1 p %2 n %3 kp2 %4\n").arg(k).arg(p).arg(n).arg(kp2)); if (kp2 < kp) kp=kp2; for(unsigned int x=0; x!=n+1; x++){ double xp = gsl_cdf_binomial_P(x, p, n); // ui->plainTextEdit->appendPlainText(QString("x %1 p %2 n %3 kp %4\n").arg(x).arg(p).arg(n).arg(xp)); double xp2 = gsl_cdf_binomial_Q(x, p, n) + gsl_ran_binomial_pdf(x, p, n); // ui->plainTextEdit->appendPlainText(QString("x %1 p %2 n %3 kp2 %4\n").arg(x).arg(p).arg(n).arg(xp2)); if (xp2 < xp) xp=xp2; double xxp = gsl_ran_binomial_pdf(x, p, n); // ui->plainTextEdit->appendPlainText(QString("x %1 p %2 n %3 xxp %4\n").arg(x).arg(p).arg(n).arg(xxp)); if (xp<=kp){ sum = sum+xxp; } // ui->plainTextEdit->appendPlainText(QString("p %1 sum %2\n").arg(p).arg(sum)); } if (sum<alpha){ pbal = p; // ui->plainTextEdit->appendPlainText(QString("sum: %1; p: %2").arg(sum).arg(p)); } else { break; } z++; } //jobb z =0; for(double p=0.9999; p>=0.0001; p = p-0.0001){ sum=0; double kp = gsl_cdf_binomial_P(k, p, n); double kp2 = gsl_cdf_binomial_Q(k, p, n) + gsl_ran_binomial_pdf(k, p, n); if (kp2 < kp) kp=kp2; for(unsigned int x=0; x!=n+1; x++){ double xp = gsl_cdf_binomial_P(x, p, n); double xp2 = gsl_cdf_binomial_Q(x, p, n) + gsl_ran_binomial_pdf(x, p, n); if (xp2 < xp) xp=xp2; double xxp = gsl_ran_binomial_pdf(x, p, n); if (xp<=kp){ sum = sum+xxp; } } // ui->plainTextEdit->appendPlainText(QString("p %1 sum %2\n").arg(p).arg(sum)); if (sum<alpha){ pjobb = p; } else { break; } z++; } } else if (dlg->m_ui->comboBox->currentText()=="Wilson"){ // ---------------------------------------------------------- // -------------------- W I L S O N ------------------------- // ---------------------------------------------------------- double zkrit = 1.96; double plusminus = zkrit * pow(pow(zkrit, 2.) + 4. * k * (n-k) / n, .5); double nevezo = 2.*(n + pow(zkrit, 2.)); pbal = (2.*k + pow(zkrit, 2) - plusminus)/nevezo; pjobb = (2.*k + pow(zkrit, 2) + plusminus)/nevezo; } else if (dlg->m_ui->comboBox->currentText()=="Clopper-Pearson"){ // ---------------------------------------------------------- // ------------- C L O P P E R P E A R S O N -------------- // ---------------------------------------------------------- //bal int z =0; for(double p=0.0001; p<=0.9999; p = p+0.0001){ double kp = gsl_cdf_binomial_Q(k, p, n) + gsl_ran_binomial_pdf(k, p, n); // ui->plainTextEdit->appendPlainText(QString("kp: %1; p: %2").arg(kp).arg(p)); if (kp<0.5*alpha){ pbal = p; } else { break; } z++; } //jobb z =0; for(double p=0.9999; p>=0.0001; p = p-0.0001){ double kp = gsl_cdf_binomial_P(k, p, n); if (kp<0.5*alpha){ pjobb = p; } else { break; } z++; } } kiir(pbal, pjobb, prev, Sp, Se); QApplication::restoreOverrideCursor(); } }
int main (int argc, char **argv) { char b; BINFA_PTR gyoker = uj_elem (); gyoker->ertek = '/'; gyoker->bal_nulla = gyoker->jobb_egy = NULL; BINFA_PTR fa = gyoker; long max=0; while (read (0, (void *) &b, 1)) { write (1, &b, 1); if (b == '0') { if (fa->bal_nulla == NULL) { fa->bal_nulla = uj_elem (); fa->bal_nulla->ertek = 0; fa->bal_nulla->bal_nulla = fa->bal_nulla->jobb_egy = NULL; fa = gyoker; } else { fa = fa->bal_nulla; } } else { if (fa->jobb_egy == NULL) { fa->jobb_egy = uj_elem (); fa->jobb_egy->ertek = 1; fa->jobb_egy->bal_nulla = fa->jobb_egy->jobb_egy = NULL; fa = gyoker; } else { fa = fa->jobb_egy; } } } printf ("\n"); kiir (gyoker); extern int max_melyseg, atlagosszeg, melyseg, atlagdb; extern double szorasosszeg, atlag; printf ("melyseg=%d\n", max_melyseg - 1); /* Átlagos ághossz kiszámítása */ atlagosszeg = 0; melyseg = 0; atlagdb = 0; ratlag (gyoker); // atlag = atlagosszeg / atlagdb; // (int) / (int) "elromlik", ezért casoljuk // K&R tudatlansági védelem miatt a sok () :) atlag = ((double) atlagosszeg) / atlagdb; /* Ághosszak szórásának kiszámítása */ atlagosszeg = 0; melyseg = 0; atlagdb = 0; szorasosszeg = 0.0; rszoras (gyoker); double szoras = 0.0; if (atlagdb - 1 > 0) szoras = sqrt (szorasosszeg / (atlagdb - 1)); else szoras = sqrt (szorasosszeg); printf ("altag=%f\nszoras=%f\n", atlag, szoras); szabadit (gyoker); }
void writeStatus2(char* s) { gotoxy(X+3,Y-1); kiir("%c - %s",getKch(1),s); cleared1=0; }
void writeStatus(char* s) { gotoxy(X+3,Y-2); kiir("%c - %s",getKch(0),s); cleared=0; }