int main(void)
{
  double ticket_cost, ticket_amount, ticket_total;
  char pick;
  bool equal= true;

    do{
        getreal(&ticket_cost,5,equal,"amount per raffle ticket");
        getreal(&ticket_amount,0, !equal, "number of raffle tickets purchased");

        ticket_total=total(ticket_cost, ticket_amount);
        show(ticket_cost, ticket_amount, ticket_total);
        do{
           pick= toupper(getValidChar("Would you like to add another? (type Y/N)\n"));
           getchar();
        }while(!(pick=='Y'||pick=='N'));
   
   }while(toupper(pick)=='Y');
    return 0;
}
Esempio n. 2
0
File: check.cpp Progetto: hrnn/olymp
int main (int argc, char * argv [])
{
 char fn [128];
 real f, m, g;
 assert (argc >= 3);
 if ((fin = fopen (argv[1], "r")) == NULL) chkexit ("No input file!", JE);
 if ((fout = fopen (argv[2], "r")) == NULL) chkexit ("No output file!", START);
 // Having no such file is allowed.
 if (argc >= 5) freopen (argv[4], "w", stderr);
 fscanf (fin, " %d %d %d", &n, &k, &test);
 answer (fout);
 fclose (fout);

 if ((fout = fopen (argv[2], "r")) == NULL) chkexit ("No output file!", START);
 getreal (fout, g);
 fclose (fout);

 sprintf (fn, "C:\\teststat\\%02d.stat", test);
 if ((fstat = fopen (fn, "a+")) == NULL)
  chkexit ("Cannot write statistics!", JE);
 foutbln (fstat, d);
 fclose (fstat);

 if ((fstat = fopen (fn, "r")) == NULL)
  chkexit ("Cannot read statistics!", JE);
 m = g;
 while (getreal (fstat, f) != EOF)
  if (m < f)
   m = f;
 fclose (fstat);

 // Currently, judge accepts Partially Correct codes in range
 // START..START + RANGE.
 fprintf (stderr, "We are going to return %d.\n",
  START + int (RANGE * (g / m)));
 chkexit ("Added to statistics.", START + int (RANGE * (g / m)));
 assert (false);
 return 0;
}
Esempio n. 3
0
static VOID make_number P2C(Number *, num, LVAL, x)
{
  if (realp(x)) {
    num->real = makefloat(x);
    num->imag = 0.0;
    num->complex = FALSE;
  }
  else if (complexp(x)) {
    num->real = makefloat(getreal(x));
    num->imag = makefloat(getimag(x));
    num->complex = TRUE;
  }
  else xlerror("not a number", x);
}
Esempio n. 4
0
void addEntry(void){
    int product_number, product_type, product_quantity;  
    double product_cost, product_price; 
    char pick;
    bool input;
   // char choice;
   
   do{
       /* User data entry*/
    getint(&product_number,1,9999, "product number");
    getint(&product_type,1,5, "product type");
    getint(&product_quantity,1,50, "product quantity");
    getreal(&product_cost,5.0,900.0,"product cost");
    getreal(&product_price,6.0,1000.0, "product price");

    show(product_number, product_type, product_quantity, product_cost, product_price);
    do{
   pick= toupper(getValidChar("Would you like to add another? (type Y/N)\n"));
   getchar();
    }while(!(pick=='Y'||pick=='N'));
       
   
   }while(toupper(pick)=='Y');
}
Esempio n. 5
0
double Tag::getvalue(unsigned int index)const{
//returns the value in float format, there might be loss of precision
switch(tagtype){
  case INTTYPE:{
    return getint(index);
    break;
    }
  case FLOATTYPE:{
    return getreal(index);
    break;
    }
  case CHARTYPE:{
    return gettagchar(index);
    break;
    }
  }
return 0;
}
Esempio n. 6
0
/*
 * process the option at 'argv[i]'
 * Params:
 * 	*table	the element to process
 *	arg	the argument if any
 *
 * returns <0 on error
 */
static int
process( optionT *table, const char *arg )
{	int nRet=0;
	typedef void (*callbackT)(void);

	assert( table );
	if( !table->data )
		return -1;

	/* TODO: next time do the questions on a table! */
	switch( table->type )
	{	case OPT_T_FLAG:
		case OPT_T_NFLAG:
			*((int *)table->data) = table->type == OPT_T_FLAG;
			break;
		case OPT_T_INT:
			nRet = getint(arg,table->data);
			break;
		case OPT_T_LONG:
			nRet = getlong(arg,table->data);
			break;
		case OPT_T_REAL:
			nRet = getreal(arg,table->data);
			break;
		case OPT_T_FUNCT:
			(*(callbackT)table->data)();
			break;
		case OPT_T_GENER:
			*((const char **)table->data) = arg;
			break;
		default:
			assert( 0 );
	}
	
	return nRet;	
}
Esempio n. 7
0
inline complex complexAP::to_complex() const
{
  return complex(getreal(), getimaginary());
}
Esempio n. 8
0
inline void complexAP::sprint(char* s)
{
  sprintf(s, "(%lf) + i*(%lf)", getreal(), getimaginary());
}
Esempio n. 9
0
static void multi_menu(void)
{
        int catchint;

        catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
        if (catchint) {
                if (setjmp(jmpbuf) != 0)
                        fprintf(stdout,"\n.. Interrupt\n");
#ifdef UNIX
                if (signal(SIGINT,jumper) == BADSIG)
                        fprintf(stdout,"Error: signal\n");
#else
                if (signal(SIGINT,SIG_DFL) == (void*)BADSIG)
                        fprintf(stdout,"Error: signal\n");
#endif
        }


	if(dnaflag) {
		gap_open   = dna_gap_open;
		gap_extend = dna_gap_extend;
	}
	else {
		gap_open   = prot_gap_open;
		gap_extend = prot_gap_extend;
	}

	while(TRUE) {

		fprintf(stdout,"\n\n\n");
		fprintf(stdout," ********* MULTIPLE ALIGNMENT PARAMETERS *********\n");
		fprintf(stdout,"\n\n");
		
		fprintf(stdout,"     1. Gap Opening Penalty              :%4.2f\n",gap_open);
		fprintf(stdout,"     2. Gap Extension Penalty            :%4.2f\n",gap_extend);

		fprintf(stdout,"     3. Delay divergent sequences        :%d %%\n\n",(pint)divergence_cutoff);

                fprintf(stdout,"     4. DNA Transitions Weight           :%1.2f\n\n",transition_weight);
                fprintf(stdout,"     5. Protein weight matrix            :%s\n"
                                        	,matrix_menu.opt[matnum-1].title);
                fprintf(stdout,"     6. DNA weight matrix                :%s\n"
                                        	,dnamatrix_menu.opt[dnamatnum-1].title);
		fprintf(stdout,"     7. Use negative matrix              :%s\n\n",(!neg_matrix) ? "OFF" : "ON");
                fprintf(stdout,"     8. Protein Gap Parameters\n\n");
		fprintf(stdout,"     H. HELP\n\n\n");		

		getstr("Enter number (or [RETURN] to exit)",lin2);

		if(*lin2 == EOS) {
			if(dnaflag) {
				dna_gap_open    = gap_open;
				dna_gap_extend  = gap_extend;
			}
			else {
				prot_gap_open   = gap_open;
				prot_gap_extend = gap_extend;
			}
			return;
		}
		
		switch(toupper(*lin2)) {
			case '1':
			fprintf(stdout,"Gap Opening Penalty Currently: %4.2f\n",gap_open);
				gap_open=(float)getreal("Enter number",(double)0.0,(double)100.0,(double)gap_open);
				break;
			case '2':
				fprintf(stdout,"Gap Extension Penalty Currently: %4.2f\n",gap_extend);
				gap_extend=(float)getreal("Enter number",(double)0.0,(double)10.0,(double)gap_extend);
				break;
			case '3':
				fprintf(stdout,"Min Identity Currently: %d\n",(pint)divergence_cutoff);
				divergence_cutoff=getint("Enter number",0,100,divergence_cutoff);
				break;
			case '4':
				fprintf(stdout,"Transition Weight Currently: %1.2f\n",(pint)transition_weight);
				transition_weight=(float)getreal("Enter number",(double)0.0,(double)1.0,(double)transition_weight);
				break;
			case '5':
                                matnum = read_matrix("PROTEIN",matrix_menu,mtrxname,matnum,usermat,aa_xref);
				break;
			case '6':
                                dnamatnum = read_matrix("DNA",dnamatrix_menu,dnamtrxname,dnamatnum,userdnamat,dna_xref);
				break;
			case '7':
				neg_matrix ^= TRUE;
				break;
			case '8':
                                gap_penalties_menu();
				break;
			case '?':
			case 'H':
				get_help('4');
				break;
			default:
				fprintf(stdout,"\n\nUnrecognised Command\n\n");
				break;
		}
	}
}
Esempio n. 10
0
static void pair_menu(void)
{
        int catchint;

        catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
        if (catchint) {
                if (setjmp(jmpbuf) != 0)
                        fprintf(stdout,"\n.. Interrupt\n");
#ifdef UNIX
                if (signal(SIGINT,jumper) == BADSIG)
                        fprintf(stdout,"Error: signal\n");
#else
                if (signal(SIGINT,SIG_DFL) == (void*)BADSIG)
                        fprintf(stdout,"Error: signal\n");
#endif
        }


        if(dnaflag) {
                pw_go_penalty     = dna_pw_go_penalty;
                pw_ge_penalty     = dna_pw_ge_penalty;
                ktup       = dna_ktup;
                window     = dna_window;
                signif     = dna_signif;
                wind_gap   = dna_wind_gap;

        }
        else {
                pw_go_penalty     = prot_pw_go_penalty;
                pw_ge_penalty     = prot_pw_ge_penalty;
                ktup       = prot_ktup;
                window     = prot_window;
                signif     = prot_signif;
                wind_gap   = prot_wind_gap;

        }

	while(TRUE) {
	
		fprintf(stdout,"\n\n\n");
		fprintf(stdout," ********* PAIRWISE ALIGNMENT PARAMETERS *********\n");
		fprintf(stdout,"\n\n");

		fprintf(stdout,"     Slow/Accurate alignments:\n\n");

		fprintf(stdout,"     1. Gap Open Penalty       :%4.2f\n",pw_go_penalty);
		fprintf(stdout,"     2. Gap Extension Penalty  :%4.2f\n",pw_ge_penalty);
		fprintf(stdout,"     3. Protein weight matrix  :%s\n" ,
                                        matrix_menu.opt[pw_matnum-1].title);
		fprintf(stdout,"     4. DNA weight matrix      :%s\n" ,
                                        dnamatrix_menu.opt[pw_dnamatnum-1].title);
		fprintf(stdout,"\n");

		fprintf(stdout,"     Fast/Approximate alignments:\n\n");

		fprintf(stdout,"     5. Gap penalty            :%d\n",(pint)wind_gap);
		fprintf(stdout,"     6. K-tuple (word) size    :%d\n",(pint)ktup);
		fprintf(stdout,"     7. No. of top diagonals   :%d\n",(pint)signif);
		fprintf(stdout,"     8. Window size            :%d\n\n",(pint)window);

                fprintf(stdout,"     9. Toggle Slow/Fast pairwise alignments ");
                if(quick_pairalign)
                      fprintf(stdout,"= FAST\n\n");
                else
                      fprintf(stdout,"= SLOW\n\n");


		fprintf(stdout,"     H. HELP\n\n\n");
		
		getstr("Enter number (or [RETURN] to exit)",lin2);
		if( *lin2 == EOS) {
                        if(dnaflag) {
                                dna_pw_go_penalty     = pw_go_penalty;
                                dna_pw_ge_penalty     = pw_ge_penalty;
                		dna_ktup       = ktup;
                		dna_window     = window;
                		dna_signif     = signif;
                		dna_wind_gap   = wind_gap;

                        }
                        else {
                                prot_pw_go_penalty     = pw_go_penalty;
                                prot_pw_ge_penalty     = pw_ge_penalty;
                		prot_ktup       = ktup;
                		prot_window     = window;
                		prot_signif     = signif;
                		prot_wind_gap   = wind_gap;

                        }
 
			return;
		}
		
		switch(toupper(*lin2)) {
			case '1':
				fprintf(stdout,"Gap Open Penalty Currently: %4.2f\n",pw_go_penalty);
				pw_go_penalty=(float)getreal("Enter number",(double)0.0,(double)100.0,(double)pw_go_penalty);
				break;
			case '2':
				fprintf(stdout,"Gap Extension Penalty Currently: %4.2f\n",pw_ge_penalty);
				pw_ge_penalty=(float)getreal("Enter number",(double)0.0,(double)10.0,(double)pw_ge_penalty);
				break;
                        case '3':
                                pw_matnum = read_matrix("PROTEIN",pw_matrix_menu,pw_mtrxname,pw_matnum,pw_usermat,pw_aa_xref);
                                break;
                        case '4':
                                pw_dnamatnum = read_matrix("DNA",dnamatrix_menu,pw_dnamtrxname,pw_dnamatnum,pw_userdnamat,pw_dna_xref);
                                break;
			case '5':
                                fprintf(stdout,"Gap Penalty Currently: %d\n",(pint)wind_gap);
                                wind_gap=getint("Enter number",1,500,wind_gap);
				break;
			case '6':
                                fprintf(stdout,"K-tuple Currently: %d\n",(pint)ktup);
                                if(dnaflag)
                                     ktup=getint("Enter number",1,4,ktup);
                                else
                                     ktup=getint("Enter number",1,2,ktup);                                     
				break;
			case '7':
                                fprintf(stdout,"Top diagonals Currently: %d\n",(pint)signif);
                                signif=getint("Enter number",1,50,signif);
				break;
			case '8':
                                fprintf(stdout,"Window size Currently: %d\n",(pint)window);
                                window=getint("Enter number",1,50,window);
				break;
                        case '9': quick_pairalign ^= TRUE;
                                break;
			case '?':
			case 'H':
				get_help('3');
				break;
			default:
				fprintf(stdout,"\n\nUnrecognised Command\n\n");
				break;
		}
	}
}
Esempio n. 11
0
int n42totxt(const char* fname){
  TH1F* h=new TH1F("n42","title", 16000,0,16000);
  TString oneline, title=fname, token;
  int MAXLINES=64000;
  int i,j;

//======================================Conversion to cmd
  char cmd[500], newname[500], basename[500], newtitle[500];
  //  sprintf(cmd, "simplexml -v RadInstrumentData/RadMeasurement/Spectrum/ChannelData  20160121-bg001.n42 | sed ':a;N;$!ba;s/\n/ /g'  |  tr \" \" \"\n\" > z.dat", fname);
  sprintf( cmd, "basename -z  %s .n42 | tr \"\\n\" \" \" > .BASENAME", fname );
  //  printf("%s\n", cmd );
  system(cmd);
  FILE* temf=fopen(".BASENAME","r");
  if (temf!=NULL){  fread( basename, 1, sizeof(basename), temf ); fclose(temf);}

  // calib
  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/EnergyCalibration/CoefficientValues %s | cut -d \" \" -f 2 > .%s.cal1 ", fname, basename );
  //  printf( "%s\n", cmd );
  system(cmd);
  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/EnergyCalibration/CoefficientValues %s | cut -d \" \" -f 1 > .%s.cal0 ", fname, basename );
  //  printf( "%s\n", cmd );
  system(cmd);


  // realtime
  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/RealTimeDuration %s | cut -b 8-9 > .%s.durD ", fname, basename );
  system(cmd);

  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/RealTimeDuration %s | cut -b 12-13 > .%s.durH ", fname, basename );
  system(cmd);

  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/RealTimeDuration %s | cut -b 15-16 > .%s.durM ", fname, basename );
  system(cmd);

  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/RealTimeDuration %s | cut -b 18-19 > .%s.durS ", fname, basename );
  system(cmd);
  int totalsec=  getvalue(basename,".durD")*24*3600+
  getvalue(basename,".durH")*3600 +
  getvalue(basename,".durM")*60 +
  getvalue(basename,".durS");
  printf("%d seconds REAL\n",totalsec);


    // livetime
  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/Spectrum/LiveTimeDuration %s | cut -b 8-9 > .%s.livD ", fname, basename );
  system(cmd);

  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/Spectrum/LiveTimeDuration %s | cut -b 12-13 > .%s.livH ", fname, basename );
  system(cmd);

  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/Spectrum/LiveTimeDuration %s | cut -b 15-16 > .%s.livM ", fname, basename );
  system(cmd);

  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/Spectrum/LiveTimeDuration %s | cut -b 18-19 > .%s.livS ", fname, basename );
  system(cmd);
  int livesec=  getvalue(basename,".livD")*24*3600+
  getvalue(basename,".livH")*3600 +
  getvalue(basename,".livM")*60 +
  getvalue(basename,".livS");
  printf("%d seconds LIVE      .....  %.2f %% deadtime\n",livesec,  100.0*(totalsec-livesec)/totalsec );

  

  printf("START TIME:\n%s","");

  // START TIME
  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/StartDateTime %s  | tr \"\\n\" \" \"  > .%s.start ", fname, basename );
  system(cmd);

  printf("moving to  /dat/  section\n%s","");


     // DATA ITSELF ===================================================
  sprintf( newname, "%s.dat", basename );
  sprintf( newtitle, "h%s", basename );
  h->SetName( newtitle );
  sprintf( newtitle, "%s  %.2f%% DT  cal: %.4f,%.4f", getchar(basename,".start") ,  100.0*(totalsec-livesec)/totalsec,   getreal(basename,".cal1"),  getreal(basename,".cal0")  );
  h->SetTitle( newtitle );

  printf("exctracting  /dat/  section ... histogram title=%s\n",  newtitle);
  sprintf(cmd, "/usr/bin/simplexml -v RadInstrumentData/RadMeasurement/Spectrum/ChannelData %s | tr \"\\n\" \" \"   |  tr \" \" \"\\n\" > %s ", fname, newname );
  //  printf( "%s\n", cmd );
  system(cmd);
  printf("  /dat/  section exctracted, oppening\n%s","");
  
  FILE * pFile;
  pFile=fopen( newname  ,"r" ); 
  if (pFile==NULL) {
    printf("cannot open %s,STOPping\n", fname ); 
    return 0;
  } // error
  
    i=0;
  int lastlen;// remove spaces
  while ((i<MAXLINES)&&( feof(pFile)==0) ){ 
    if ( oneline.Gets (pFile, kTRUE) ){//chop true ---------
      while ( ( feof(pFile)==0)&&(oneline.Length()<1) ){
	oneline.Gets (pFile, kTRUE) ;
      }
      /*      do {
	lastlen=oneline.Length();
          if (oneline.Index(" ")==0){oneline=oneline(1,oneline.Length()-1);}
      lastlen=oneline.Length();
      if (oneline.Index(" ")==lastlen){oneline=oneline(0,oneline.Length()-1);}

       oneline.ReplaceAll("\t"," ");
       oneline.ReplaceAll("  "," ");
       oneline.ReplaceAll("  "," ");
      }while( lastlen!=oneline.Length());
      */
      
      if (i<10)printf("%d  %s\n", i, oneline.Data() );
      if ((i%1000)==0)printf("%d  %s\n", i, oneline.Data() );
      for (int j=0;j<oneline.Atoi();j++){
	//	h->SetBinContent( i ,  oneline.Atof()  );
	h->Fill(  i  );
      }
      i++;
    }// if gets ------------------------------------------
    
  }// while end
  printf("  /while/  section ended\n%s","");

  h->Draw();
  h->Print();
  printf( "CALIBRATION:\n%.4f,%.4f\n", getreal(basename,".cal1"),  getreal(basename,".cal0")  );
  sprintf( newname, "%s_histo.root", basename );
  TFile* f=new TFile(newname,"update");
  h->Write();
  f->Close();
} // FUNCTION =============================================