void main() { //Deklarasi Antrian dan data penampung. Queue QFest,QTribun; Data NewVal; double TotalJumlah=0,TotalT=0,TotalF=0; int menu; //Inisialisasi Antrian CreateEmpty(&QFest); CreateEmpty(&QTribun); //showMenu do { system("CLS"); printf("===== KONSER TONG TONG BAND =====\n"); printf("1. Masukan Antrian \n"); printf("2. Tampil Antrian Tribun \n"); printf("3. Tampil Antrian Festival \n"); printf("4. Transaksi Antrian Tribun \n"); printf("5. Transaksi Antrian Festival \n"); printf("6. Jumlah Pendapatan \n"); printf("7. TUGAS - Jumlah Pendapatan \n"); printf("================================= \n"); printf(" >> Masukan Menu : "); scanf("%d",&menu); switch(menu) { case 1 ://Input Antrian printf(" Nama : "); fflush(stdin); gets(NewVal.nama); printf(" No Hp : "); fflush(stdin); gets(NewVal.no_hp); //Pemilihan Jenis Tiket while(strcmpi(NewVal.jenis_tiket,"festival")!=0 && strcmpi(NewVal.jenis_tiket,"tribun")!=0) { printf(" Jenis Tiket(festival/tribun) : "); fflush(stdin); gets(NewVal.jenis_tiket); } if(strcmpi(NewVal.jenis_tiket,"festival")==0) { //Cek AntrianFestival if (isFull(QFest)) { printf("\n antrian penuh . . ."); strcpy(NewVal.jenis_tiket,"-"); break; } //Auto Tiket NewVal.no_antrian=AutoID(&QFest); printf(" Nomor Tiket : %d \n",NewVal.no_antrian); //Prosesur Add Add(&QFest,NewVal); } if(strcmpi(NewVal.jenis_tiket,"tribun")==0) { //Cek AntrianTribun if (isFull(QTribun)) { printf("\n antrian penuh . . ."); strcpy(NewVal.jenis_tiket,"-"); break; } //Auto Tiket NewVal.no_antrian=AutoID(&QTribun); printf(" Nomor Tiket : %d \n",NewVal.no_antrian); //Prosesur Add Add(&QTribun,NewVal); } //Reset Jenis Tiket strcpy(NewVal.jenis_tiket,"-"); break; case 2 : //Cek Antrian Kosong if (isEmpty(&QTribun)) { printf("\n antrian kosong . . ."); break; } //Prosedur Show ShowQueue(QTribun); break; case 3 : //Cek Antrian Kosong if (isEmpty(&QFest)) { printf("\n antrian kosong . . ."); break; } //Prosedur Show ShowQueue(QFest); break; case 4 : if (isEmpty(&QTribun)) { printf("\n antrian kosong . . ."); break; } //Print Transaksi printf("\n ====== Transaksi Tribun====== \n"); JumlahPendapatan(QTribun,&TotalJumlah,&TotalT,&TotalF); Delete(&QTribun); break; case 5 : if (isEmpty(&QFest)) { printf("\n antrian kosong . . ."); break; } //Print Transaksi printf("\n ====== Transaksi Festival====== \n"); JumlahPendapatan(QFest,&TotalJumlah,&TotalT,&TotalF); Delete(&QFest); break; case 6 : printf("\n Total Pendapatan = %lf",TotalJumlah); break; case 7 : printf("\n Total Pendapatan Tribun = %lf",TotalT); printf("\n Total Pendapatan Festival = %lf",TotalF); printf("\n---------------------------------------- ++"); printf("\n Total Pendapatan = %lf",TotalT+TotalF); break; case 8 : printf(" Head %d \n",QTribun.head); printf(" Tail %d \n",QTribun.tail); } getch(); } while(menu!=0); }
main() { int index = 0; int size = 0; pMem pOwnHead;//原始内存链表 pMem pGetHead;//分配内存链表 pGet pGetaddr = NULL;//记录链表 pGet temp_addr ; init_memory(&pOwnHead);//初始化头结点 create_memory(pOwnHead,10);//创建10个结构体 init_memory(&pGetHead);//初始化分配内存链表 init_get_addr(&pGetaddr);// 初始化记录链接表 temp_addr = pGetaddr; while(index!=5) { printf("输入要进行的操作:\n"); printf(" 1--------Create\n"); printf(" 2--------Delete\n"); printf(" 3--------Display the free space\n"); printf(" '5'--------Exit\n"); scanf("%d",&index); switch(index) { case CREATE: { printf("输入要开辟的空间:\n"); scanf("%d",&size); get_memory(pOwnHead,pGetHead,pGetaddr,size); }break; case DELETE: { if(temp_addr->next!=pGetaddr) { free_memory(pOwnHead,pGetHead,temp_addr->next); temp_addr = temp_addr->next; } }break; case DISPLAY1: { printf("空闲的空间为:\n"); display_free(pOwnHead); printf("已经分配的空间为:\n"); display_free(pGetHead); }break; case '5':break; default:break; } } }
int main() { /** * @var Рабочая матрица. */ int matrix[MAX_MATRIX_SIZE][MAX_MATRIX_SIZE]; /** * @var Размер матрицы. */ int size; /** * @vars Переменные для индексов строк и столбцов. */ int i, j; /** * @var Переменная для обхода матрицы при линеаризации. */ int k; /** * @var Флаг направления движения "наискосок". * Если он четный, то двигаться надо * вниз по строкам и вправо по столбцам. * Если он нечетный, то двигаться надо * вверх по строкам и влево по столбцам. */ int direction = 1; /** * @var Флаг изменения строк. */ bool_t is_row_changed = TRUE; /** * @var Флаг изменения столбцов. */ bool_t is_col_changed = TRUE; /* * Cчитываем размер матрицы. */ scanf("%d", &size); /* * Защита от дурака. */ if(!((0 <= size) && (size <= MAX_MATRIX_SIZE))){ printf("wrong input\n"); return 1; } /* * Cчитываем саму матрицу. */ for(i = 0; i != size; ++i) for(j = 0; j != size; ++j) scanf("%d", &matrix[i][j]); /* * Обход и печать матрицы */ i = size - 1; j = 0; printf("%d ", matrix[i][j]); for(k = 1; k <= size * size - 1; ++k){ if( (TRUE == is_row_changed) && ( ( /* матрица четная */ (0 == (size % 2)) && (0 != i) && ((0 == j) || ((size - 1) == j)) ) || ( /* матрица нечетная */ (0 != (size % 2)) && (0 != i) && ((size - 1) != i) && ((0 == j) || ((size - 1) == j)) ) || ( (size - 1 == i) && (0 == j) ) ) ){ if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d\n", k, i, j, matrix[i][j] ); } /* * Идем вверх по стокам. */ --i; is_row_changed = FALSE; is_col_changed = TRUE; if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d (up)\n", k, i, j, matrix[i][j] ); } } else if( (TRUE == is_col_changed) && ( ( (0 == (size % 2)) && ((size - 1) != j) && (0 != j) && ((0 == i) || ((size - 1) == i)) ) || ( (0 != (size % 2)) && ((0 == i) || ((size - 1) == i)) ) ) ){ if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d\n", k, i, j, matrix[i][j] ); } /* * Идем вправо по столбцам. */ ++j; is_row_changed = TRUE; is_col_changed = FALSE; if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d (right)\n", k, i, j, matrix[i][j] ); } } else if(0 != (direction % 2)) { if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d\n", k, i, j, matrix[i][j] ); } /* * Идем вниз по строкам и вправо по столбцам. */ ++i; ++j; if(((size - 1) == i) || ((size - 1) == j)){ ++direction; } is_row_changed = TRUE; is_col_changed = TRUE; if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d (down, right)\n", k, i, j, matrix[i][j] ); } } else { if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d\n", k, i, j, matrix[i][j] ); } /* * Идем вверх по строкам и влево по столбцам. */ --i; --j; if ((0 == i) || (0 == j)){ ++direction; } is_col_changed = TRUE; is_row_changed = TRUE; if(DEBUG){ /* Отладочная печать */ fprintf( stderr, "%d, matrix[%d][%d] = %d (top, left)\n", k, i, j, matrix[i][j] ); } } printf("%d ", matrix[i][j]); } printf("\n"); return 0; }
int main(){ clrscr(); //Registros struct FILIA { char PAI[40]; char MAE[40]; }; struct DATANASC { int DIA; int MES; int ANO; }; struct ENDER{ char RUA[30]; char NUMERO[10]; char COMPLEMENTO[30]; char BAIRRO[30]; char CIDADE[30]; }; struct FUNCIONARIO { char NOME[40]; struct FILIA FILIACAO; struct DATANASC DTNASC; struct ENDER ENDERECO; int QTDAT; }; //Constantes const int MAX = 1; const int COR1 = 10; const int COR2 = 12; //Variaveis struct FUNCIONARIO FUNC[30]; int I,Cor,C,ANOATUAL; //Inicializacao Variaveis Cor = 0; C = 0; ANOATUAL = 0; //Leitura for(I = 0; I < MAX; I++){ //NOME do{ printf("Entre com o Nome do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].NOME); }while(FUNC[I].NOME == ""); //PAI do{ printf("\n"); printf("Entre com o Nome do Pai do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].FILIACAO.PAI); }while(FUNC[I].FILIACAO.PAI == ""); //MAE do{ printf("\n"); printf("Entre com o Nome da Mae do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].FILIACAO.MAE); }while(FUNC[I].FILIACAO.MAE == ""); //DIA do{ printf("\n"); printf("Entre com o Dia de Nascimento do %i° Funcionário: ",(I+1)); scanf("%i",&FUNC[I].DTNASC.DIA); }while(FUNC[I].DTNASC.DIA < 0 && FUNC[I].DTNASC.DIA > 31); //MES do{ printf("\n"); printf("Entre com o Mes de Nascimento do %i° Funcionário: ",(I+1)); scanf("%i",&FUNC[I].DTNASC.MES); }while(FUNC[I].DTNASC.MES < 0 && FUNC[I].DTNASC.MES > 12); //ANO do{ printf("\n"); printf("Entre com o Ano de Nascimento do %i° Funcionário: ",(I+1)); scanf("%i",&FUNC[I].DTNASC.ANO); }while(FUNC[I].DTNASC.ANO < 0); //RUA do{ printf("\n"); printf("Entre com a Rua do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].ENDERECO.RUA); }while(FUNC[I].ENDERECO.RUA == ""); //NUMERO do{ printf("\n"); printf("Entre com o Numero do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].ENDERECO.NUMERO); }while(FUNC[I].ENDERECO.NUMERO == ""); //COMPLEMENTO do{ printf("\n"); printf("Entre com o Complemento do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].ENDERECO.COMPLEMENTO); }while(FUNC[I].ENDERECO.COMPLEMENTO == ""); //BAIRRO do{ printf("\n"); printf("Entre com o Bairro do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].ENDERECO.BAIRRO); }while(FUNC[I].ENDERECO.BAIRRO == ""); //CIDADE do{ printf("\n"); printf("Entre com a Cidade do %i° Funcionário: ",(I+1)); scanf("%s",&FUNC[I].ENDERECO.CIDADE); }while(FUNC[I].ENDERECO.CIDADE == ""); //QTDAT do{ printf("\n"); printf("Entre com a Quantidade de Anos Trabalhados do %i° Funcionário: ",(I+1)); scanf("%i",&FUNC[I].QTDAT); }while(FUNC[I].QTDAT < 0); //Ano Atual do{ printf("\n"); printf("Entre com o Ano Atual: "); scanf("%i",&ANOATUAL); }while(ANOATUAL < 0); } //Processamento printf("\n\nFuncionários com mais de 30 Anos de Idade e 10 Trabalhados\n\n"); printf("--\t Funcionario"); printf("\n"); for(I = 0; I < MAX; I++){ //Cor if(Cor%2 == 0){ textcolor(COR1); }else{ textcolor(COR2); } //Resultado if(((ANOATUAL - FUNC[I].DTNASC.ANO) > 30) && (FUNC[I].QTDAT > 10)){ if(C<10 && C>=0){ // até 9 cprintf("00%i",(C+1)); printf("\t"); cprintf("%s",FUNC[I].NOME); printf("\n"); Cor +=1; C+=1; }else if(C>=10 && C<100){ //10 até 99 cprintf("0%i",(C+1)); printf("\t"); cprintf("%s",FUNC[I].NOME); printf("\n"); Cor +=1; C+=1; }else if(C>=100){ // acima de 100 cprintf("%i",(C+1)); printf("\t"); cprintf("%s",FUNC[I].NOME); printf("\n"); Cor +=1; C+=1; } } } if(C == 0){ printf("\t"); cprintf("Nenhum Funcionario =>%i - %i = %i",ANOATUAL,FUNC[0].DTNASC.ANO,(ANOATUAL-FUNC[0].DTNASC.ANO)); } //Impressao Valores Lidos //Muito Extenso Oo getch(); return 0; }
int main (void) { ListaNotas l; char nota[1024]; int posicion; int opcion; int final = 0; iniciarListaNotas(l); do { /* Mostrar el menu de opciones */ printf("\n"); printf("Notas\n"); printf("-----\n"); printf("\n"); printf(" 1.- Listar las notas\n"); printf(" 2.- Insertar una nota\n"); printf(" 3.- Borrar una nota\n"); printf(" 0.- Salir\n"); printf("\n"); printf("\n"); printf(" Introduzca su opción: "); fflush(stdout); scanf ("%d",&opcion); switch(opcion){ case 1: /* Listar las notas */ printf("\n"); printf("... Notas .......................................\n"); mostrarNotas(l); printf(".................................................\n"); break; case 2: /* Insertar una nota */ printf("Introduzca el contenido de la nota:\n"); fflush(stdout); do { fgets(nota,MAX_TAM_NOTA,stdin); } while ( (!strcmp(nota,"\n")) || (!strcmp(nota,"")) ) ; insertarNota(l, nota); break; case 3: /* Borrar una nota */ printf("Introduzca la posición de la nota a borrar: "); fflush(stdout); scanf("%d",&posicion); borrarNota(l,posicion); break; case 0: /* Salir del menu */ final=1; break; default: /* la opción elegida no esta dentro de las indicadas */ printf("La opcion elegida es incorrecta\n\n"); } } while (0 == final); destruirListaNotas(l); return (0); }
int main( int argc, char *argv[ ], char *envp[ ] ) { char temp[5] ; char path_elements[200] = "data\\base\\elements" ; char path_map[200] = "data\\maps\\map" ; int path_map_def = 0; char path_los[200] = "data\\maps\\map" ; int path_los_def = 0; long i=0, mapnum=0 ; int j; CClos_TextOutput = 1 ; if ( argc > 1 ) { for ( j = 1 ; j < argc ; j++ ) { if (argv[j][0] == '+' || argv[j][0] == '-') { switch (argv[j][1]) { case 'T': CClos_TextOutput = 0 ; break; case 'M': strcpy ( path_map , argv[j+1] ) ; add_backslash ( path_map ) ; strcat ( path_map , "map" ) ; path_map_def = 1 ; if ( !path_los_def) strcpy ( path_los , path_map ) ; break ; case 'L': strcpy ( path_los , argv[j+1] ) ; add_backslash ( path_los ) ; strcat ( path_los , "map" ) ; path_los_def = 1 ; if ( !path_map_def) strcpy ( path_map , path_los ) ; break ; case 'E': strcpy ( path_elements , argv[j+1] ) ; break ; case 'N': i = sscanf ( argv[j+1] , "%d" , &mapnum ) ; break ; } } } } if (CClos_TextOutput) printf ("CC2 LOS calculation - v0.99b\n"); while ( i == 0 || mapnum > 999 ) { if (!CClos_TextOutput) return -8; printf ("enter map number : "); i = scanf ( "%d" , &mapnum ) ; if ( i == 0 ) printf ("only the number...\n"); if ( mapnum > 999 ) printf ("number too hight...\n"); if ( i != 0 && mapnum < 999 ) printf ("\n"); } sprintf ( temp , "%03d" , mapnum ) ; strcat ( path_map , temp ) ; strcat ( path_los , temp ) ; strcat ( path_los , ".los" ) ; fflush ( stdin ) ; i = LOScalculate ( path_map, path_los, path_elements ) ; if (CClos_TextOutput) switch (i) { case 0: printf ( "All OK!\n" ) ; getchar (); break ; case -1: printf ( "ERROR : bad map file\n" ) ; getchar (); break ; case -2: printf ( "ERROR : bad elements file\n" ) ; getchar (); break ; case -3: printf ( "ERROR : not enough memory\n" ) ; getchar (); break ; case -4: printf ( "ERROR : map file not found\n" ) ; getchar (); break ; case -5: printf ( "ERROR : element file not found\n" ) ; getchar (); break ; case -6: printf ( "ERROR : can't create LOS file\n" ) ; getchar (); break ; case -7: printf ( "ERROR : can't write in LOS file (disk full)\n" ) ; getchar (); break ; case -8: printf ( "ERROR : bad element in map\n" ) ; getchar (); break ; } if (CClos_TextOutput) return 0 ; else return i ; }
int main() { static long long int ch[7][100005],ce[7][100005],cf[7][100005],hf[7][100005],ef[7][100005],he[7][100005],l,r,i,j,n,res,p1,p2,whole,aapas,door,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12; char ar[1000006],a,b; scanf("%s",ar); scanf("%lld",&n); for(i=0,j=1;ar[i]!='\0';i++) { if(ar[i]=='c') { //ch ch[1][j]=ch[1][j-1]+1; ch[2][j]=ch[2][j-1]+0; p1=p1-ch[2][j]; ch[3][j]=p1; ch[5][j]=ch[5][j-1]+1; ch[4][j]=ch[4][j-1]+0; ch[6][j]=p2; //ce //cf j++; } else if(ar[i]=='h') { //hc ch[2][j]=ch[2][j-1]+1; ch[1][j]=ch[1][j-1]+0; ch[3][j]=ch[3][j-1]+0; ch[4][j]=ch[4][j-1]+1; ch[5][j]=ch[5][j-1]+0; p2=p2-ch[5][j]; ch[6][j]=p2; //hf //he j++; } } //ce for(i=0,j=1;ar[i]!='\0';i++) { if(ar[i]=='c') { ce[1][j]=ce[1][j-1]+1; ce[2][j]=ce[2][j-1]+0; p3=p3-ce[2][j]; ce[3][j]=p3; ce[5][j]=ce[5][j-1]+1; ce[4][j]=ce[4][j-1]+0; ce[6][j]=p4; j++; } else if(ar[i]=='e') { ce[2][j]=ce[2][j-1]+1; ce[1][j]=ce[1][j-1]+0; ce[3][j]=ce[3][j-1]+0; ce[4][j]=ce[4][j-1]+1; ce[5][j]=ce[5][j-1]+0; p4=p4-ce[5][j]; ce[6][j]=p4; j++; } } //hf for(i=0,j=1;ar[i]!='\0';i++) { if(ar[i]=='h') { hf[1][j]=hf[1][j-1]+1; hf[2][j]=hf[2][j-1]+0; p5=p5-hf[2][j]; hf[3][j]=p5; hf[5][j]=hf[5][j-1]+1; hf[4][j]=hf[4][j-1]+0; hf[6][j]=p6; j++; } else if(ar[i]=='f') { hf[2][j]=hf[2][j-1]+1; hf[1][j]=hf[1][j-1]+0; hf[3][j]=hf[3][j-1]+0; hf[4][j]=hf[4][j-1]+1; hf[5][j]=hf[5][j-1]+0; p6=p6-hf[5][j]; hf[6][j]=p6; j++; } } //ef for(i=0,j=1;ar[i]!='\0';i++) { if(ar[i]=='e') { ef[1][j]=ef[1][j-1]+1; ef[2][j]=ef[2][j-1]+0; p7=p7-ef[2][j]; ef[3][j]=p7; ef[5][j]=ef[5][j-1]+1; ef[4][j]=ef[4][j-1]+0; ef[6][j]=p8; j++; } else if(ar[i]=='f') { ef[2][j]=ef[2][j-1]+1; ef[1][j]=ef[1][j-1]+0; ef[3][j]=ef[3][j-1]+0; ef[4][j]=ef[4][j-1]+1; ef[5][j]=ef[5][j-1]+0; p8=p8-ef[5][j]; ef[6][j]=p8; j++; } } //he for(i=0,j=1;ar[i]!='\0';i++) { if(ar[i]=='h') { he[1][j]=he[1][j-1]+1; he[2][j]=he[2][j-1]+0; p9=p9-he[2][j]; he[3][j]=p9; he[5][j]=he[5][j-1]+1; he[4][j]=he[4][j-1]+0; he[6][j]=p10; j++; } else if(ar[i]=='e') { he[2][j]=he[2][j-1]+1; he[1][j]=he[1][j-1]+0; he[3][j]=he[3][j-1]+0; he[4][j]=he[4][j-1]+1; he[5][j]=he[5][j-1]+0; p10=p10-he[5][j]; he[6][j]=p10; j++; } } //cf for(i=0,j=1;ar[i]!='\0';i++) { if(ar[i]=='c') { cf[1][j]=cf[1][j-1]+1; cf[2][j]=cf[2][j-1]+0; p11=p11-cf[2][j]; cf[3][j]=p11; cf[5][j]=cf[5][j-1]+1; cf[4][j]=cf[4][j-1]+0; cf[6][j]=p12; j++; } else if(ar[i]=='f') { cf[2][j]=cf[2][j-1]+1; cf[1][j]=cf[1][j-1]+0; cf[3][j]=cf[3][j-1]+0; cf[4][j]=cf[4][j-1]+1; cf[5][j]=cf[5][j-1]+0; p12=p12-cf[5][j]; cf[6][j]=p12; j++; } } for(i=1;i<=6;i++) { for(j=1;j<=10;j++) { printf("%lld ",ce[i][j]); }printf("\n"); } while(n--) { scanf("\n%c\n%c\n%lld%lld",&a,&b,&l,&r); if(a=='c'&&b=='h') { whole=ch[1][r]*ch[2][r]+ch[3][r]; aapas=ch[1][l-1]*ch[2][l-1]+ch[3][l-1]; door=ch[1][l-1]*(ch[2][r]-ch[2][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='h'&&b=='c') { whole=ch[4][r]*ch[5][r]+ch[6][r]; aapas=ch[4][l-1]*ch[5][l-1]+ch[6][l-1]; door=ch[4][l-1]*(ch[5][r]-ch[5][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='c'&&b=='e') { whole=ce[1][r]*ce[2][r]+ce[3][r]; aapas=ce[1][l-1]*ce[2][l-1]+ce[3][l-1]; door=ce[1][l-1]*(ce[2][r]-ce[2][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='e'&&b=='c') { whole=ce[4][r]*ce[5][r]+ce[6][r]; aapas=ce[4][l-1]*ce[5][l-1]+ce[6][l-1]; door=ce[4][l-1]*(ce[5][r]-ce[5][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='h'&&b=='f') { whole=hf[1][r]*hf[2][r]+hf[3][r]; aapas=hf[1][l-1]*hf[2][l-1]+hf[3][l-1]; door=hf[1][l-1]*(hf[2][r]-hf[2][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='f'&&b=='h') { whole=hf[4][r]*hf[5][r]+hf[6][r]; aapas=hf[4][l-1]*hf[5][l-1]+hf[6][l-1]; door=hf[4][l-1]*(hf[5][r]-hf[5][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='e'&&b=='f') { whole=ef[1][r]*ef[2][r]+ef[3][r]; aapas=ef[1][l-1]*ef[2][l-1]+ef[3][l-1]; door=ef[1][l-1]*(ef[2][r]-ef[2][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='f'&&b=='e') { whole=ef[4][r]*ef[5][r]+ef[6][r]; aapas=ef[4][l-1]*ef[5][l-1]+ef[6][l-1]; door=ef[4][l-1]*(ef[5][r]-ef[5][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='h'&&b=='e') { whole=he[1][r]*he[2][r]+he[3][r]; aapas=he[1][l-1]*he[2][l-1]+he[3][l-1]; door=he[1][l-1]*(he[2][r]-he[2][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='e'&&b=='h') { whole=he[4][r]*he[5][r]+he[6][r]; aapas=he[4][l-1]*he[5][l-1]+he[6][l-1]; door=he[4][l-1]*(he[5][r]-he[5][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='c'&&b=='f') { whole=cf[1][r]*cf[2][r]+cf[3][r]; aapas=cf[1][l-1]*cf[2][l-1]+cf[3][l-1]; door=cf[1][l-1]*(cf[2][r]-cf[2][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } else if(a=='f'&&b=='c') { whole=cf[4][r]*cf[5][r]+cf[6][r]; aapas=cf[4][l-1]*cf[5][l-1]+cf[6][l-1]; door=cf[4][l-1]*(cf[5][r]-cf[5][l-1]); res=whole-(aapas+door); printf("%lld\n",res); } } return 0; }
int main (void){ int cont=1; do{ int a=0,b=0,c=0; float sum=0; char grade; //Have the user enter the three seperate grades. Make sure the grades are in the proper parameters. //First midterm do{ printf("Please enter the student's grade for the first midterm of a student using percanitles (0-100): "); scanf("%d", &a); if(a<0||a>100) printf("Your percentile was not valid. Please use the numbers 1-100.\n"); }while(a<0||a>100); //Second midterm do{ printf("Please enter the student's grade for the second midterm of a student using percentiles (0-100): "); scanf("%d", &b); if(b<0||b>100) printf("Your percentile was not valid. Please use the numbers 1-100.\n"); }while(b<0||b>100); //Third midterm do{ printf("Please enter the studen't grade for the final exam of the class using percentiles (0-100): "); scanf("%d", &c); if(c<0||c>100) printf("Your percentile was not valid. Please use the numbers 1-100.\n"); }while(c<0||c>100); //Print the student's highest grade of the 3 tests printf("This student's highest grade was on their "); if(a>b&&a>c) printf("first midterm, scoring %d percent.",a); if(b>a&&b>c) printf("second midterm, scoring %d percent.",b); if(c>a&&c>b) printf("final exam, scoring %d percent.",c); //Print the student's lowest grade printf("\nThis student's lowest grade was on their "); if(a<b&&a<c) printf("first midterm, scoring %d percent.",a); if(b<a&&b<c) printf("second midterm, scoring %d percent.",b); if(c<a&&c<b) printf("final exam, scoring %d percent.",c); //Calculate the letter grade sum=(((float)a+(float)b+(float)c)/3); if (sum>=90) grade='A'; else if (sum>=80) grade='B'; else if (sum>=70) grade='C'; else if (sum>=60) grade='D'; else grade='F'; printf("\nStudent's Grade: %c, %.2f percent.", grade, sum); //Ask if they want to continue (or terminate the loop) printf("\nWould you like to exit?\n0 to exit, 1 to use the program again: "); scanf("%d", &cont); } while (cont == 1); return 0; }
/* Inicializacao do programa */ int main(){ int n_contatos = 0; // Conta o numero de contatos ja inseridos int resp, telefone_lido, i; contato agenda[70]; char parametro, inicial; char nome_lido[TAM]; bool ordenado = False; /* Inicialmente a agenda não esta ordenada */ do{ parametro = getchar(); switch(parametro){ case('i'): /* Insere um novo contato na agenda */ getchar(); scanf("%d", &(agenda[n_contatos].tel)); getchar(); scanf("%[^\n]", agenda[n_contatos].nome); getchar(); //for(i = 0; i <= n_contatos; i++) // printf("%d****%-40s %d\n", n_contatos, agenda[i].nome, agenda[i].tel); n_contatos++; ordenado = False; break; case('r'): /* Faz a remocao de um contato da agenda */ if(n_contatos > 0){ getchar(); scanf("%d", &telefone_lido); getchar(); resp = buscaTelefone(agenda, telefone_lido, n_contatos); if(resp == -1) printf("Nao foi possivel remover: Contato inexistente!\n\n"); else{ printf("Contato: %-40s %d\nFoi removido com sucesso!\n\n", agenda[resp].nome, agenda[resp].tel); remover(agenda, resp, n_contatos); n_contatos--; } } else printf("Nao foi possivel remover: Contato inexistente!\n\n"); break; case('n'): /* Busca um nome na agenda */ if(ordenado == False){ // separa(agenda, 0, n_contatos); ordenaNome(agenda, 0, n_contatos-1); ordenado = True; } getchar(); scanf("%[^\n]", nome_lido); getchar(); resp = buscaNome(agenda, nome_lido, 0, n_contatos); if(resp == -1) printf("Contato nao encontrado!\n\n"); else printf("%-40s %d\n\n", agenda[resp].nome, agenda[resp].tel); break; case('t'): /* Busca um telefone na agenda */ getchar(); scanf("%d", &telefone_lido); getchar(); resp = buscaTelefone(agenda, telefone_lido, n_contatos); if(resp == -1) printf("Contato nao encontrado!\n\n"); else printf("%-40s %d\n\n", agenda[resp].nome, agenda[resp].tel); break; case('p'): /* Faz a impressao de todos os contatos em ordem alfabetica */ if(ordenado == False){ ordenaNome(agenda, 0, n_contatos-1); ordenado = True; } if(n_contatos > 0){ /* Se nao existem contatos na agenda entao nao e necessario imprimir */ inicial = agenda[0].nome[0]; printf("----%c----\n", inicial); for(i = 0; i < n_contatos; i++){ if(agenda[i].nome[0] == inicial) printf("%-40s %d\n", agenda[i].nome, agenda[i].tel); else{ printf("----%c----\n", agenda[i].nome[0]); inicial = agenda[i].nome[0]; printf("%-40s %d\n", agenda[i].nome, agenda[i].tel); } } putchar('\n'); } else printf("\n"); break; } } while(parametro != 'f'); // system("pause"); return 0; }
int main( int argc, char **argv ) { /****************************************************************************************** Random number guessing game in a couple of lines. "Not pretty, but fairly short" version. *******************************************************************************************/ #ifdef NBR_GAME #define P printf int r, a=4, i=0, A=1, Z=10; srand(time(0)); for( P("%d..%d\n",A,Z),r=(rand()%(Z-A+1))+A; r^i&&(a--?P("(try %d/4)?:",4-a): !P("Comp wins! (was:%d)",r)); ) { scanf("%d",&i); P("%s\n",r>i?"Mine's >":r<i?"Mine's <":"Got it.\nYou win!"); } #endif /****************************************************************************************** A version of Mastermind, but based on numbers, not colors (http://en.wikipedia.org/wiki/Mastermind_(game)) *******************************************************************************************/ #ifdef MM_GAME #define DIGITS 3 char inp[10] = {0}, nr[DIGITS+1] = {0}; int i, guess = 0, rplace = 0, wplace = 0; srand(time(NULL)); for( i = 0; i < DIGITS; i++ ) nr[i] = '0' + rand() % 10; while( rplace != DIGITS ) { printf("\n Enter number (%d digits): ", DIGITS); scanf("%s3", &inp); rplace = wplace = 0; guess++; for( i = 0; i < DIGITS; i++ ) { if (inp[i] == nr[i]) rplace++; else if (strchr(nr,inp[i])) wplace++; } printf("\n Right place: %d, Wrong place: %d, attempts: %d", rplace, wplace, guess ); } puts("\n Got it!"); #endif /****************************************************************************************** Minimal passwort / token generator, based on a formated input string. Example: 5000x0xxx first digit (in HEX): generate 5 results each '0': replace with random number each 'x': replace with random character *******************************************************************************************/ #ifdef PWDGEN #define MAXLEN 20 int i, r; char inp[MAXLEN] = {0}, outp[MAXLEN] = {0}; printf("\nInput:"); scanf("%s20", &inp); if ( *inp >='a' && *inp <='f' ) r = *inp-'a'+10; else if ( *inp >='0' && *inp <='9' ) r = *inp-'0'; srand( time(NULL) ); while(r--) { for(i = 1; i < strlen(inp); i++) outp[i-1] = (inp[i]=='0') ? outp[i-1]='0' + rand() % 10: (inp[i]=='x') ? outp[i-1]='a' + rand() % 26: inp[i]; printf("\n (%2.d) pwd: %s", r + 1, outp); } #endif /****************************************************************************************** Minimal ANSI art viewer. Work in progress. *******************************************************************************************/ #ifdef ANSIART #define ESC 0x1B #define LEFTBRACKET '[' char * filename = "ab-onion.ans"; char * out[100][80]; char inp, c, a, b; int i, count = 0; int x, y, sx, sy; for( y = 0; y < 100; y++ ) for( x = 0; x < 80; x++ ) { out[y][x] = 0x20; } FILE *f = fopen(filename, "r"); if(f == NULL) { printf("\nError opening file <%s>\n", filename); return -1; } else { printf("\nReading file <%s>", filename); /* cache file first */ char in[200*80] = {'\0'}; i = 0; while( (in[i++] = fgetc(f)) != EOF && i < 100*80 ); fclose(f); printf("\nDone reading file (%d bytes).\n", i); system("PAUSE"); x = y = sx = sy = 0; i = -1; while( in[++i] ) { if (in[i] != ESC) { //printf("\nline: %d, x: %d -> %c", y,x,in[i]); out[y][x] = in[i]; if (in[i] == '\n') y++; x++; } else if ( in[i] == ESC && in[i+1] == LEFTBRACKET ) { /* interpret sequence */ /* crs up -> CSI n A */ /* crs down -> CSI n B */ /* crs forw -> CSI n C */ /* crs back -> CSI n D */ /* crs next line -> CSI n E */ /* crs prev line -> CSI n F */ /* crs horz absol-> CSI n G */ /* save position -> CSI s */ /* restore position -> CSI r */ char cmds[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 's', 'r' }; /* TODO: look for trailing command first */ i += 2; char param = in[i]; char command = in[i+1]; if(param == 's') { sx = x; sy = y; } if(param == 'r') { x = sx; y = sy; } switch(command) { case 'A': y -= param; break; case 'B': y += param; break; case 'C': x += param; break; case 'D': x -= param; break; case 'E': x = 0; y += param; break; case 'F': x = 0; y -= param; break; case 'G': x = param; break; case ';': a = in[i+2]; b = in[i+3]; if (b =='f' || b == 'H') { x = a; y = param; } break; } } else { /* ... */ } } printf("\n Buffer contents: \n"); for( y = 0; y < 80; y++ ) for( x = 0; x < 100; x++ ) { printf( "%c", out[y][x] ); } } #endif /****************************************************************************************** Tiny memory editor / viewer / file dumper utility. Enough features to have its own little help screen. :) *******************************************************************************************/ #ifdef MEDT #define KEY_ADR 'i' #define KEY_ASCII 'a' #define KEY_HEX 'h' #define KEY_DUMP 'd' #define KEY_FILL 'f' #define KEY_REPL 'r' #define KEY_HELP '?' #define KEY_QUIT 'q' #define CHAR_DUMMY '.' char *adr; char inp[40] = {0}; char *mstart = (char*)inp; char *mend = mstart + 0xFF; int cont = 1; printf("\nMEDT - 1.0a; %c = help", KEY_HELP); while (cont) { printf("\n\n[adr: %X-%X]>:", mstart, mend); scanf("%s40", inp); if (*inp == KEY_HELP) { printf("\n %c - This help screen", KEY_HELP); printf("\n %c - Input memory adress range", KEY_ADR); printf("\n %c - Display range as ASCII chars", KEY_ASCII); printf("\n %c - Display range as HEX values", KEY_HEX); printf("\n %c - Save range as a file", KEY_DUMP); printf("\n %c - Fill range with byte", KEY_FILL); printf("\n %c - Search and replace byte in range with byte", KEY_REPL); printf("\n %c - Quit\n", KEY_QUIT); } else if (*inp == KEY_ADR) { int adr1, adr2; printf("\nAdresses (HEX) [start, end]:"); scanf("%X, %X", &adr1, &adr2); mstart = (char*)adr1; mend = (char*)adr2; } else if (*inp == KEY_FILL) { int val; printf("\nFill with byte (HEX) [value]: "); scanf("%X", val); for( adr = mstart; adr < mend; adr++ ) *adr = val & 0xFF; } else if (*inp == KEY_REPL) { int val1, val2; int count = 0; printf("\nSearch and replace byte x with value y (HEX) [x, y]: "); scanf("%X,%X", &val1, &val2 ); for( adr = mstart; adr < mend; adr++ ) { if (*adr == (val1 & 0xFF)) { *adr = val2 & 0xFF; count++; } } printf("\n%d bytes found and replaced.\n", count); } else if (*inp == KEY_ASCII) { printf("\nMemory at (ASCII display mode): %X - %X\n\n", mstart, mend); /* printable 7Bit ASCII chars only, DUMMY_CHAR for the rest, 60 chars each line */ for( adr = mstart; adr < mend; adr++ ) { printf("%c%s", (*adr >= 0x20 && *adr <= 0x7E) ? *adr : CHAR_DUMMY, !((adr - mstart + 1) % 60) ? "\n" : "" ); } } else if (*inp == KEY_HEX) { printf("\nMemory at (HEX display mode): %X - %X\n\n", mstart, mend); /* separated hex values, 20 per line. leading 0, if needed */ for( adr = mstart; adr < mend; adr++ ) { char val = *adr & 0x0F; printf("-%s%X%s", (val < 0x10) ? "0" : "", val, !((adr - mstart + 1) % 20) ? "\n" : "" ); } } else if (*inp == KEY_DUMP) { char filename[80] = ""; printf("\nPath/filename: "); scanf("%s80", filename); printf("\nWriting file to disk... "); FILE *f = fopen(filename,"wb"); if (f != NULL) { for( adr = mstart; adr < mend; adr++ ) fputc(*adr & 0xFF, f); fclose(f); printf("done.\n"); } else printf("Error!\n"); } if ( !strcmp(inp,"exit") || *inp == KEY_QUIT ) cont = 0; } #endif /****************************************************************************************** A version of Picross. A Logic / Picture Puzzle Game. Unfinished. (http://en.wikipedia.org/wiki/Picross) *******************************************************************************************/ #ifdef PICROSS_GAME #define F_SIZE 10 #define PIC_COUNT 2 #define BASE_CHAR 0x22 #define CODE_CHAR 97 int i,i2, x,y, cx,cy,cn; char f[F_SIZE*F_SIZE] = {0}; char n[F_SIZE] = {0}; char nh[F_SIZE][F_SIZE]; /* hor: line, row */ char nv[F_SIZE][F_SIZE]; /* ver: line, row */ memset( nh, 0, sizeof(nh) ); memset( nv, 0, sizeof(nv) ); char pics[PIC_COUNT][F_SIZE*F_SIZE]; strcpy( pics[0], "-------------oooo-----o-o--o---o---o--o-o-----oooo-o---o--o---o-o--o-----oooo-----------------------" ); strcpy( pics[1], "-------------ooo------o--o-----o---oooooo--------oo--------o-o---ooooo--o--o-------ooo--------------" ); strcpy( pics[2], "" ); /* => 110, 101, 102, 98, 98, 98, 99, .. - 97 + 13 o 97 + 4 - 97 + 5 o 97 + 1 - 97 + 1 o 97 + 1 - 97 + 2 ... */ /* lv1 lv2 lv3 - - - - - - - - - - - - - - - - - - - - o o o o o o o o - o - - - o o o o - - - - - - o o o - - - - - - - o - - - o - o - - o - o - - o - - - - o - - o - - - - o - o o - o o o - - - o - - - o - - o - - o - - - o o o o o o - - - - - - o - o o - - - - - o o o o o - - - - - - - - o o o o - - - - o - o - o - - - o - - o - o - - - - - - - - o - o - - o o o o - o - - o - o - - o - - - o - - - o o o o o - o - - - - o - - - - - - o o o o - - - - - o - - o - - - - o o o o o - o o - o - - - - - - - - - - - - - o o o - - - - o - - - - - - - - o - - - - - - - - - - - - - - - - - - - - o o o o o o o o o o */ /*----------------------------------------------------------------------------------*/ /* select random pic, or a randomly generated pic */ if ( rand()%(PIC_COUNT+1) < PIC_COUNT ) { int cell = 0; char set = 0; /* decode pic data, if needed */ /* for(i = 0; i < strlen(pics[lv]); i++ ) { int inrow = pics[lv][i] - CODE_CHAR; for(i2 = 0; i2 < inrow; i2++ ) f[cell++] = set; set = !set; } */ /* no decoding */ for(i = 0; i < sizeof(f); i++) f[i] = (pic[lv][i] == 'o') ? 1 : 0; } else { srand( time(NULL) ); for(i = 0; i < sizeof(f); i++) f[i] = rand() % 5 ? 0 : 1; } /*----------------------------------------------------------------------------------*/ int inpx = 0, inpy = 0, cont = 1, turns = 0; /* main input loop; */ while( cont ) { /* scan field -> horizontal [TODO: vertical; outter: x, inner: y] */ for(y = 0, cy = 0; y < F_SIZE; y++) { /* start with no row results */ memset(n, 0, F_SIZE); for( x = 0, cx = 0, cn = 0; x < F_SIZE; x++ ) { /* count stones in a row */ if ( f[x + F_SIZE*y] ) cx++; /* gap or corner stone? -> add results to n[] */ if (cx && (!f[x+F_SIZE*y] || x == F_SIZE-1) ) { n[cn++] = cx + '0'; cx = 0; } } /* nh = string together all horizontal results, line breaks after each line */ strcat(n, strlen(n) ? "": "none"); strcat(nh[y], n); } /* show field + right hints per line */ for( i = 1; i <= sizeof(f); i++ ) { printf( "%c", f[i-1] + BASE_CHAR ); if ( !(i % F_SIZE) ) printf(" %s\n", nh[(i-1)/F_SIZE] ); } /* bottom hints; test with HOR. hint numbers; TODO for vert. numbers */ for( i = 0; i < F_SIZE; i++ ) { int validln = 0; char row[F_SIZE+1] = {0}; for(i2 = 0; i2 < F_SIZE; i2++) if ((row[i2] = nh[i2][i] ? nh[i2][i] : ' ') != ' ') validln = 1; if (validln) printf("%s\n", row); } /*----------------------------------------------------------------------------------*/ printf("\nTurn: %d, Enter x,y (0..9, 0..9, diff. coords to quit):", ++turns); scanf("%i,%i", &inpx, &inpy); /* check for exit */ cont = ( (inpx*inpy) >= 0) && ((inpx*inpy) < sizeof(f) ); if (cont) { printf("%d, %d -> %s", inpx, inpy, f[F_SIZE * inpy + inpx] ? "Hit!" : "Miss!" ); f[F_SIZE*inpy + inpx] = 0; /* no stones left to uncover? level complete */ char fclear = 1; for( i = 0; i < F_SIZE && (fclear = !f[i]); i++ ) if(fclear) { printf("\Pic uncovered (in %d turns)! Congratulation", turns); cont = 0; } } } system("PAUSE"); #endif /****************************************************************************************** Estimation Game Guess what number is the most common in a random number field. *******************************************************************************************/ #ifdef EST_GAME #define F_SIZE 14 #define DIFFICULTY 5 int i, a, nr, higher = 0, ce[DIFFICULTY] = {0}; char f[ F_SIZE * F_SIZE ] = {0}; time_t t = time(NULL); srand(t); puts(""); for(i = 0; i < F_SIZE * F_SIZE; i++) { printf(" %d%s", nr = rand() % DIFFICULTY, ! ((i+1)%F_SIZE) ? "\n" : "" ); ce[nr]++; } printf("\n Most common? :"); scanf("%10d", &a); for(i = 0; i < DIFFICULTY; i++) if (a != i && ce[i] > ce[a]) higher++; if ( !higher ) printf(" Correct! (in: %d seconds)", time(NULL)-t); else printf(" Wrong! (%d other number(s) are more common)", higher); printf("\n Counts: "); for(i = 0; i < DIFFICULTY; i++) printf("%d = %d%s ", i, ce[i], (i != DIFFICULTY-1) ? "," : "." ); puts("\n"); system("PAUSE"); #endif /****************************************************************************************** (Text-)file appending / copy / filter tool - can add EOF text markers - filter out extended ASCII - convert Umlauts and Esszett - apply 1990s style l33t sp34k ;) *******************************************************************************************/ #ifdef FMERGE #define MAX_FILE_COUNT 99 /* TODO: currently only works with markers + one add. flag */ char HELP_TEXT[] = "\nUsage: fmerge [parameters]\n" "\nFirst parameter not recognized as an option = output filename." "\nAll other unrecognized parameters following = input filename(s)." "\n\nOptions:" "\n --m : Insert EOF markers." "\n --d : Convert Umlaut and Esszett characters." "\n --7 : 7 Bit ASCII only. Extented ASCII chars will be replaced with a dash." "\n --l : L33t Sp43k filter.\n" "\nNote that --d, --7 and --l cannot be mixed."; char infilenames[ MAX_FILE_COUNT ][250]; char outfilename[250]; FILE *infile, *outfile; char norm_chars[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char leet_chars[] = "4bcd3fgh1jklmn0pqr5+uvwxyz" "48CD3FGH1JK7MNOPQR$+UVWXYZ"; char de_chars[] = "הצ�ִײ��"; char flag_markers = 0, flag_deconv = 0, flag_7bit = 0, flag_leet = 0; char fcount = 0, c; int i, pos; /* cmd line checking .. - first unrecognized option/parameter = output filename - all other unrecognized parameters after = input filenames */ if (argc > 2) { for( i = 1; i < argc; i++ ) { if (!strcmp(argv[i], "--m")) flag_markers = 1; else if (!strcmp(argv[i], "--d")) flag_deconv = 1; else if (!strcmp(argv[i], "--7")) flag_7bit = 1; else if (!strcmp(argv[i], "--l")) flag_leet = 1; else { if (fcount > 0) strncpy( infilenames[fcount-1], argv[i], 250 ); else strncpy( outfilename, argv[i], 250 ); fcount++; } } } if (fcount < 2) { puts("Error: At least one input and one output file required."); puts(HELP_TEXT); return -1; } if ( (flag_deconv + flag_7bit + flag_leet) > 1) { puts("Error: Too many parameters." "Only one of the following parameters permitted per run: --f, --7, --l"); puts(HELP_TEXT); return -1; } outfile = fopen( outfilename, "wb" ); printf("\Appending %d file(s) and save as <%s>\n", fcount-1, outfilename); printf( "\nFlags Overview:" "\n - 7bit only : %s" "\n - DE-Char Conv : %s" "\n - L33T sp34k : %s" "\n - EOF-Markers : %s\n", flag_7bit ? "yes" : "no", flag_deconv ? "yes" : "no", flag_leet ? "yes" : "no", flag_markers ? "yes" : "no" ); for( i = 0; i < fcount-1; i++ ) { infile = fopen(infilenames[i], "rb"); if (infile) { if (flag_leet) { while ( (c = fgetc(infile)) != EOF) { if ( (pos = (strchr(norm_chars, c) - norm_chars)) >= 0 ) fputc( leet_chars[pos], outfile); else fputc(c, outfile); } } else if (flag_7bit) { while ( (c = fgetc(infile)) != EOF) if (c >= 0) fputc(c, outfile); else fputc('-', outfile); } else if (flag_deconv) { char oldc; while ( (c = fgetc(infile)) != EOF ) if ( (pos = (strchr(de_chars, c) - de_chars)) >= 0 ) { if (pos == 0) fputs("ae", outfile); if (pos == 1) fputs("oe", outfile); if (pos == 2) fputs("ue", outfile); if (pos == 3) fputs("AE", outfile); if (pos == 4) fputs("OE", outfile); if (pos == 5) fputs("UE", outfile); /* since there's no capital Esszett, we need some context for conversion */ if (pos == 6) { fputs( (oldc >= 0x61) ? "ss" : "SS", outfile); } } else fputc(oldc = c, outfile); } if (flag_markers) { char marker[200] = "\r\n---- end of file < "; strncat( marker, infilenames[i], 160 ); strcat( marker, " > ----\r\n" ); fputs( marker, outfile ); } printf( "\n<%s> Ok.", infilenames[i] ); } else printf( "\n<%s> Error opening file", infilenames[i] ); fclose( infile ); } fclose( outfile ); puts(""); #endif /****************************************************************************************** Fisher-Yates / Durstenfeld-Shuffle with presets (useful for searching for anagrams or just trying to come up with project names ;) *******************************************************************************************/ #ifdef PERM #define LOOPS 20 int i, j, r; char inp[40], tmp; srand(time(NULL)); printf("String to shuffle, [shortcuts: a-z, 0-9, dice]: "); scanf("%s40", &inp); if ( !strcmp(inp, "a-z" ) ) strcpy(inp, "abcdefghijklmnopqrstuvwxyz"); if ( !strcmp(inp, "0-9" ) ) strcpy(inp, "0123456789"); if ( !strcmp(inp, "dice") ) strcpy(inp, "123456"); for( j = LOOPS; j-- > 0; ) { for( i = strlen(inp); i-- > 1; ) { r = rand() % i; tmp = inp[i]; inp[i] = inp[r]; inp[r] = tmp; } printf("<%s>\n", inp); } system("PAUSE"); #endif /****************************************************************************************** SBFED = Super Bad File Encoding & Decoding (shortest and possibly worst mini file encrypter/decrypter possible. Don't use this for your billion dollar trade secrets. ;) *******************************************************************************************/ #ifdef SBFED if (argc != 3) { puts("Error: 2 params for in/out files needed."); return -1; }; FILE *sf = fopen( argv[1], "rb"); FILE *df = fopen( argv[2], "wb"); char c; while( (c = fgetc(sf)) != EOF ) fputc( (((c^-1) & 0xF0) >> 4) | (((c^-1) & 0x0F) << 4), df ); fclose(sf); fclose(df); #endif /****************************************************************************************** Prime Number Evaluation. Short, simple & fast enough. AKS this is not, though. *******************************************************************************************/ #ifdef PRIME /* Beware: C99 stuff. ANSI/C89-only compilant compilers might argue this. */ long long int i, p, isprime = 1; printf("\nNumber:"); scanf("%lld", &p); if (p == 2) isprime = 1; else if (p < 2 || !(p % 2)) isprime = 0; else for(i = 3; ( i <= sqrt(p)) && (isprime = p % i); i += 2); printf("\nPrime: %s\n", isprime ? "Yes" : "No"); #endif /****************************************************************************************** (ANTI-)JOKE GENERATOR. NOTHING IS SACRED! "Why did the charming bulldozer run over the research facility?" "Because the bulldozer could not love a(n) upset aroma therapist!" *******************************************************************************************/ #ifdef AJOKE srand(time(NULL)); char *a[] = { "chicken", "astronaut", "bulldozer", "aroma therapist", "pole dancer" }; char *b[] = { "cross", "run over", "walk over", "talk to", "love" }; char *c[] = { "street", "bridge", "chicken farm", "rumba instructor meeting hall", "research facility" }; char *d[] = { "bossy", "charming", "single", "blushing", "upset" }; printf("\nWhy did the %s %s %s the %s?", d[rand()%5], a[rand()%5], b[rand()%5], c[rand()%5] ); printf("\nBecause the %s could not %s a(n) %s %s!\n", a[rand()%5], b[rand()%5], d[rand()%5], a[rand()%5] ); #endif return 0; }
int main(int ac, char *av[]) { int i, NumTests, testNum, partial_match; char *arg, *test_name; int count; int testToRun = -1; for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++) { } NumTests = count; /* If no test name was given */ /* process command line with user function. */ if (ac < 2) { /* Ask for a test. */ printf("Available tests:\n"); for (i =0; i < NumTests; ++i) { printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name); } printf("To run a test, enter the test number: "); fflush(stdout); testNum = 0; if( scanf("%d", &testNum) != 1 ) { printf("Couldn't parse that input as a number\n"); return -1; } if (testNum >= NumTests) { printf("%3d is an invalid test number.\n", testNum); return -1; } testToRun = testNum; ac--; av++; } partial_match = 0; arg = 0; /* If partial match is requested. */ if(testToRun == -1 && ac > 1) { partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0; } if (partial_match && ac < 3) { printf("-R needs an additional parameter.\n"); return -1; } if(testToRun == -1) { arg = lowercase(av[1 + partial_match]); } for (i =0; i < NumTests && testToRun == -1; ++i) { test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name); if (partial_match && strstr(test_name, arg) != NULL) { testToRun = i; ac -=2; av += 2; } else if (!partial_match && strcmp(test_name, arg) == 0) { testToRun = i; ac--; av++; } free(test_name); } if(arg) { free(arg); } if(testToRun != -1) { int result; result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av); return result; } /* Nothing was run, display the test names. */ printf("Available tests:\n"); for (i =0; i < NumTests; ++i) { printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name); } printf("Failed: %s is an invalid test name.\n", av[1]); return -1; }
int main (void) { int year, month, day; double lon, lat; double len, rise, set, cur_time; int rc; char ch; time_t t; struct tm *tm; t = time (NULL); tm = gmtime (&t); lon = 0; sun_rise_set (tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, lon, 0.0, &rise, &set); cur_time = tm->tm_hour + tm->tm_min / 60.0; lon += (rise - cur_time) * 15.0; if (lon > 180.0) lon -= 360.0; if (lon < -180.0) lon += 360.0; printf ("==> Sun is rising at longitude %5.2fE, latitude 0.00N\n", lon); printf ("Longitude (+ is east) and latitude (+ is north), or * for Lugano: "); ch = getchar (); if (ch == '*') lon = 8.0 + 57.0/60.0, lat = 46.0; else { ungetc (ch, stdin); while (scanf ("%lf %lf", &lon, &lat) < 2) ; } tm = localtime (&t); year = tm->tm_year + 1900; month = tm->tm_mon + 1; day = tm->tm_mday; do { len = day_length (year, month, day, lon, lat); printf ("==> Day length: %5.2f hours\n", len); rc = sun_rise_set (year, month, day, lon, lat, &rise, &set); if (rc == 1) printf ("==> Sun never sets!\n"); else if (rc == -1) printf ("==> Sun never rises!\n"); else { printf ("==> Midday: %5.2f GMT\n", (rise + set) / 2); printf ("==> Sunrise: %5.2f, Sunset: %5.2f GMT\n", rise, set); } rc = civil_rise_set (year, month, day, lon, lat, &rise, &set); if (rc == 1) printf ("==> Sun never reaches civil dusk!\n"); else if (rc == -1) printf ("==> Sun never reaches civil dawn!\n"); else printf ("==> Civil sunrise: %5.2f, Sunset: %5.2f GMT\n", rise, set); printf ("Date (yyyy mm dd) (ctrl-C exits): "); while (scanf ("%d %d %d", &year, &month, &day) < 3 && !feof (stdin)) ; } while (!feof (stdin)); return 0; }
int main(int argc, char *argv[]) { int a; int b; scanf("%d", &a); // printf("%d\n", a); while(a != 0) { int i; int num_digits_in_binary = 0; int start = 0, end = 0; for(i=0; i<20; i++) { binary[i] = 0; } num_digits_in_binary = get_binary_from_decimal(a); // printf("n digits : %d\n", num_digits_in_binary); // for(i=0; i<num_digits_in_binary; i++) // printf("%d", binary[i]); // // printf("\n"); for(i=0; i< num_digits_in_binary; i++) { if(binary[i] == 1) { start = i; break; } } for(i=start; i< num_digits_in_binary; i++) { if(i == num_digits_in_binary -1) { end = i; num_digits_in_binary++; break; } if(binary[i+1] == 0 ) { end = i; break; } } // printf("%d, %d\n", start, end); if(start == end) { binary[start + 1] = 1; binary[start] = 0; } else { int x = start; while(x <= end) { binary[x] = 0; x++; } binary[end+1] = 1; x = 0; while(x < (end-start)) { binary[x] = 1; x++; } } // for(i=0; i<num_digits_in_binary; i++) // printf("%d", binary[i]); // // printf("\n"); int n = binary_to_decimal(num_digits_in_binary); printf("%d\n", n); // printf("\n\n"); scanf("%d", &a); // printf("%d\n", a); } return 0; }
void fixParameters() { int counter, testid; // Check to see if any parameterized tests are selected if ( (testVector[TEST_BLOCK_FREQUENCY] != 1) && (testVector[TEST_NONPERIODIC] != 1) && (testVector[TEST_OVERLAPPING] != 1) && (testVector[TEST_APEN] != 1) && (testVector[TEST_SERIAL] != 1) && (testVector[TEST_LINEARCOMPLEXITY] != 1) ) return; do { counter = 1; printf(" P a r a m e t e r A d j u s t m e n t s\n"); printf(" -----------------------------------------\n"); if ( testVector[TEST_BLOCK_FREQUENCY] == 1 ) printf(" [%d] Block Frequency Test - block length(M): %d\n", counter++, tp.blockFrequencyBlockLength); if ( testVector[TEST_NONPERIODIC] == 1 ) printf(" [%d] NonOverlapping Template Test - block length(m): %d\n", counter++, tp.nonOverlappingTemplateBlockLength); if ( testVector[TEST_OVERLAPPING] == 1 ) printf(" [%d] Overlapping Template Test - block length(m): %d\n", counter++, tp.overlappingTemplateBlockLength); if ( testVector[TEST_APEN] == 1 ) printf(" [%d] Approximate Entropy Test - block length(m): %d\n", counter++, tp.approximateEntropyBlockLength); if ( testVector[TEST_SERIAL] == 1 ) printf(" [%d] Serial Test - block length(m): %d\n", counter++, tp.serialBlockLength); if ( testVector[TEST_LINEARCOMPLEXITY] == 1 ) printf(" [%d] Linear Complexity Test - block length(M): %d\n", counter++, tp.linearComplexitySequenceLength); printf("\n"); printf(" Select Test (0 to continue): "); scanf("%1d", &testid); printf("\n"); counter = 0; if ( testVector[TEST_BLOCK_FREQUENCY] == 1 ) { counter++; if ( counter == testid ) { printf(" Enter Block Frequency Test block length: "); scanf("%d", &tp.blockFrequencyBlockLength); printf("\n"); continue; } } if ( testVector[TEST_NONPERIODIC] == 1 ) { counter++; if ( counter == testid ) { printf(" Enter NonOverlapping Template Test block Length: "); scanf("%d", &tp.nonOverlappingTemplateBlockLength); printf("\n"); continue; } } if ( testVector[TEST_OVERLAPPING] == 1 ) { counter++; if ( counter == testid ) { printf(" Enter Overlapping Template Test block Length: "); scanf("%d", &tp.overlappingTemplateBlockLength); printf("\n"); continue; } } if ( testVector[TEST_APEN] == 1 ) { counter++; if ( counter == testid ) { printf(" Enter Approximate Entropy Test block Length: "); scanf("%d", &tp.approximateEntropyBlockLength); printf("\n"); continue; } } if ( testVector[TEST_SERIAL] == 1 ) { counter++; if ( counter == testid ) { printf(" Enter Serial Test block Length: "); scanf("%d", &tp.serialBlockLength); printf("\n"); continue; } } if ( testVector[TEST_LINEARCOMPLEXITY] == 1 ) { counter++; if ( counter == testid ) { printf(" Enter Linear Complexity Test block Length: "); scanf("%d", &tp.linearComplexitySequenceLength); printf("\n"); continue; } } } while ( testid != 0 ); }
void newcustomer() { char ans; char att; char ebaggage[10]; char baggageoptions[10]; char name[50]; char start[5]; char destination[5]; char baddress[30]; char mop[5]; char pass1[500]; char pass2[500]; int i; int k; int n; int time; int phonenumber; int membnumber; int total = 0; int fareb = 1450; int farec = 2999; int fared = 7832; int fareh = 1999; int farek = 4560; int farem = 3570; int ccn; float gtotal; printf("\n Enter the name under which you would want the booking to be done: "); scanf("%s",name); printf("\n The available airports are:\nBangalore\nChennai\nDelhi\nHyderabad\nKolkata\nMumbai\n"); printf("\n Enter the starting point of your journey: "); printf("\n Enter B for Bangalore, C for Chennai, D for Delhi, H for Hyderabad, K for Kolkata and M for Mumbai.\n "); scanf("%s",start); printf("\n Select your destination among the above mentioned cities."); printf("\n Enter B for Bangalore, C for Chennai, D for Delhi, H for Hyderabad, K for Kolkata and M for Mumbai.\n "); scanf("%s",destination); printf("\n How many people will you be booking for? "); scanf("%d",&n); printf("\n Enter your address: "); scanf("%s",baddress); fflush(stdin); printf("\n Enter your phone number: "); scanf("%d",&phonenumber); printf("\n Kindly proceed with the booking. "); system("cls"); if((strcmp(destination,"B")==0)||(strcmp(destination,"b")==0)) { printf("\n Your destination is Bangalore."); printf("\n Flights are available only on week ends."); printf("\n The flights are available at:\n 0700hours\n 1230hours\n 1600hours\n 2330hours\n"); printf("Please enter your preferred time:"); scanf("%d",&time); if(time==700) { printf("\n Your flight number is AFT1235"); printf("\n The air travel would last 1 hour. "); } else if(time==1230) { printf("\n Your flight number is ZER3698"); printf("\n The air travel would last 1 hour. "); } else if(time==1600) { printf("\n Your flight number is LUO2367"); printf("\n The air travel would last 1 hour. "); } else if(time==2330) { printf("\n Your flight number is GTE4561"); printf("\n The air travel would last 1 hour. "); } else { printf("Sorry!The flight is not available at the time you mentioned."); } total = fareb*n; } if((strcmp(destination,"C")==0)||(strcmp(destination,"c")==0)) { printf("\n Your destination is Chennai."); printf("\n Flights are available daily."); printf("\n The flights are available at:\n 0830hours\n 1130hours\n 1630hours\n 2300hours\n"); printf("Please enter your preferred time:"); scanf("%d",&time); if(time==830) { printf("\n Your flight number is AFT1235"); printf("\n The air travel would last 1 hour 45 minutes. "); } else if(time==1130) { printf("\n Your flight number is ZER3698"); printf("\n The air travel would last 1 hour 45 minutes. "); } else if(time==1630) { printf("\n Your flight number is LUO2367"); printf("\n The air travel would last 1 hour 45 minutes. "); } else if(time==2300) { printf("\n Your flight number is GTE4561"); printf("\n The air travel would last 1 hour 45 minutes. "); } else { printf("Sorry!The flight is not available at the time you mentioned."); } total = farec*n; } if((strcmp(destination,"D")==0)||(strcmp(destination,"d")==0)) { printf("\n Your destination is Delhi."); printf("\n Flights are available daily."); printf("\n The flights are available at:\n 0530hours\n 1300hours\n 1730hours\n 2230hours\n"); printf("Please enter your preferred time:"); scanf("%d",&time); if(time==530) { printf("\n Your flight number is AFT1235"); printf("\n The air travel would last 2 hour 30 minutes. "); } else if(time==1300) { printf("\n Your flight number is ZER3698"); printf("\n The air travel would last 2 hour 30 minutes. "); } else if(time==1730) { printf("\n Your flight number is LUO2367"); printf("\n The air travel would last 2 hour 30 minutes. "); } else if(time==2230) { printf("\n Your flight number is GTE4561"); printf("\n The air travel would last 2 hour 30 minutes. "); } else { printf("Sorry!The flight is not available at the time you mentioned."); } total = fared*n; } if((strcmp(destination,"H")==0)||(strcmp(destination,"h")==0)) { printf("\n Your destination is Hyderabad."); printf("\n Flights are available only on weekends."); printf("\n The flights are available at:\n 0630hours\n 1100hours\n 1430hours\n 2130hours\n"); printf("Please enter your preferred time:"); scanf("%d",&time); if(time==630) { printf("\n Your flight number is AFT1235"); printf("\n The air travel would last 1 hour 30 minutes. "); } else if(time==1100) { printf("\n Your flight number is ZER3698"); printf("\n The air travel would last 1 hour 30 minutes. "); } else if(time==1430) { printf("\n Your flight number is LUO2367"); printf("\n The air travel would last 1 hour 30 minutes. "); } else if(time==2130) { printf("\n Your flight number is GTE4561"); printf("\n The air travel would last 1 hour 30 minutes. "); } else { printf("Sorry!The flight is not available at the time you mentioned."); } total = fareh*n; } if((strcmp(destination,"K")==0)||(strcmp(destination,"k")==0)) { printf("\n Your destination is Kolkata"); printf("\n Flights are available only on weekends."); printf("\n The flights are available at:\n 0600hours\n 1145hours\n 1420hours\n 2145hours\n"); printf("Please enter your preferred time:"); scanf("%d",&time); if(time==600) { printf("\n Your flight number is AFT1235"); printf("\n The air travel would last 2 hours."); } else if(time==1145) { printf("\n Your flight number is ZER3698"); printf("\n The air travel would last 2 hours."); } else if(time==1420) { printf("\n Your flight number is LUO2367"); printf("\n The air travel would last 2 hours."); } else if(time==2145) { printf("\n Your flight number is GTE4561"); printf("\n The air travel would last 2 hours."); } else { printf("Sorry!The flight is not available at the time you mentioned."); } total = farek*n; } if((strcmp(destination,"M")==0)||(strcmp(destination,"m")==0)) { printf("\n Your destination is Mumbai."); printf("\n Flights are available daily."); printf("\n The flights are available at:\n 0545hours\n 1120hours\n 1430hours\n 2200hours\n"); printf("Please enter your preferred time:"); scanf("%d",&time); if(time==545) { printf("\n Your flight number is AFT1235"); printf("\n The air travel would last 1 hour 30 minutes. "); } else if(time==1120) { printf("\n Your flight number is ZER3698"); printf("\n The air travel would last 1 hour 30 minutes. "); } else if(time==1430) { printf("\n Your flight number is LUO2367"); printf("\n The air travel would last 1 hour 30 minutes. "); } else if(time==2200) { printf("\n Your flight number is GTE4561"); printf("\n The air travel would last 1 hour 30 minutes. "); } else { printf("Sorry!The flight is not available at the time you mentioned."); } total = farem*n; } system("sleep 1200"); system("cls"); printf("\n Enter the passenger details.\n\n"); for(i=0;i<n;i++) { printf("\n \n Enter Passenger %d's Name: ",i+1); scanf("%s",passenger[i].name); printf("\n Enter Passenger %d's Age: ",i+1); scanf("%d",&passenger[i].age); printf("\n Enter F for Female and M for Male: "); scanf("%s",passenger[i].gender); printf("\n Which class do you prefer? - Economy or Business. \n\t\t Enter E for Economy and B for Business. \n\t"); scanf("%s",passenger[i].travelclass); printf("\n Which type of meal would you prefer? - On flight, Vegetarian or Non.Vegetarian."); printf("\t\t Enter O for On-flight,V for Vegetarian and N for Non-Vegetarian. \n\t"); scanf("%s",passenger[i].meal); printf("\n Which seat would you prefer? - Aisle, Middle, Window"); printf("\n\t\t Enter A for Aisle, M for Middle and W for Window. \n\t"); scanf("%s",passenger[i].seat); if(passenger[i].age<=12||passenger[i].age>60) { printf("\n Do you need an attendant to accompany you?: \n\t\t Enter Y for Yes and N for No.\n\t"); scanf("%s" ,att); } if((strcmp(passenger[i].travelclass,"B")==0)||(strcmp(passenger[i].travelclass,"b")==0)) { total = total + 500; } if((strcmp(passenger[i].meal,"V")==0)||(strcmp(passenger[i].meal,"v")==0)) { total = total + 200; } if((strcmp(passenger[i].meal,"N")==0)||(strcmp(passenger[i].meal,"n")==0)) { total = total + 375; } system("sleep 800"); system("cls"); } printf("\n Will you be carrying extra baggage?"); printf("\n\t\t Enter Y if you are,and N if you won't be carrying extra baggage.\n\t"); scanf("%s",ebaggage); if((strcmp(ebaggage,"Y")==0)||(strcmp(ebaggage,"y")==0)) { printf("\n It will cost you Rs.600 for 5 kgs."); } printf("\n \n Do you require your baggage to be put on priority or fragile?"); printf("\n\t\t Enter P for Priority Baggage, F for Fragile Baggage and N for None.\n\t"); scanf("%s",baggageoptions); printf("\n The total fare would be Rs.%d",total); printf("\n Would you like to pay by card or cash? \n\t"); scanf("%s",mop); if(strcmp(mop,"card")==0) { gtotal = total + 0.02*total; printf("\n Enter your credit card number. "); scanf("%d",&ccn); ab: printf("\n Enter the Password: "******"*"); } printf("\n Enter the password again: "); for(k = 0; k< 500; k++) { pass2[k] = getchar(); if(pass2[k] == 13) { pass2[k] = 0; break; } printf("*"); } if(!strcmp(pass2,pass1)) { printf("\n You have succesfully completed the transaction. "); } else { printf("\n Transaction failed."); goto ab; } } if(strcmp(mop,"cash")==0) { gtotal = total + 0.005*total; printf("\n The total amount payable in cash is %f",gtotal); } system("cls"); printf("\n Here are your flight details:\n\n\n "); if(strcmp(start,"B")==0||strcmp(start,"b")==0) { printf("Place of Departure: Bangalore"); } if(strcmp(start,"C")==0||strcmp(start,"c")==0) { printf("\n Place of Departure: Chennai"); } if(strcmp(start,"D")==0||strcmp(start,"d")==0) { printf("\n Place of Departure: Delhi"); } if(strcmp(start,"H")==0||strcmp(start,"h")==0) { printf("\n Place of Departure: Hyderabad"); } if(strcmp(start,"K")==0||strcmp(start,"k")==0) { printf("\n Place of Departure: Kolkata"); } if(strcmp(start,"M")==0||strcmp(start,"m")==0) { printf("\n Place of Departure: Mumbai"); } if(strcmp(destination,"B")==0||strcmp(destination,"b")==0) { printf("\n Place of Arrival: Bangalore"); } if(strcmp(destination,"C")==0||strcmp(destination,"c")==0) { printf("\n Place of Arrival: Chennai"); } if(strcmp(destination,"D")==0||strcmp(destination,"d")==0) { printf("\n Place of Arrival: Delhi"); } if(strcmp(destination,"H")==0||strcmp(destination,"h")==0) { printf("\n Place of Arrival: Hyderabad"); } if(strcmp(destination,"K")==0||strcmp(destination,"k")==0) { printf("\n Place of Arrival: Kolkata"); } if(strcmp(destination,"M")==0||strcmp(destination,"m")==0) { printf("\n Place of Arrival: Bangalore"); } printf("\n Please note that the check-in closes 45 minutes before boarding time."); printf("\n Do not forget to carry your identification with you at all times."); printf("\n Have a safe journey."); }
int generatorOptions(char** streamFile) { char file[200]; int option = NUMOFGENERATORS+1; FILE *fp; while ( (option < 0) || (option > NUMOFGENERATORS) ) { option = displayGeneratorOptions(); switch( option ) { case 0: printf("\t\tUser Prescribed Input File: "); scanf("%s", file); *streamFile = (char*)calloc(200, sizeof(char)); sprintf(*streamFile, "%s", file); printf("\n"); if ( (fp = fopen(*streamFile, "r")) == NULL ) { printf("File Error: file %s could not be opened.\n", *streamFile); exit(-1); } else fclose(fp); break; case 1: *streamFile = "Linear-Congruential"; break; case 2: *streamFile = "Quadratic-Congruential-1"; break; case 3: *streamFile = "Quadratic-Congruential-2"; break; case 4: *streamFile = "Cubic-Congruential"; break; case 5: *streamFile = "XOR"; break; case 6: *streamFile = "Modular-Exponentiation"; break; case 7: *streamFile = "Blum-Blum-Shub"; break; case 8: *streamFile = "Micali-Schnorr"; break; case 9: *streamFile = "G using SHA-1"; break; /* INTRODUCE NEW PRNG NAMES HERE */ /* case 10: *streamFile = "myNewPRNG"; break; */ default: printf("Error: Out of range - Try again!\n"); break; } } return option; }
int main() { scanf("%d", &a); printf(a % 2 ? "odd\n" : "even\n"); return 0; }
int main(){ int i, res, escolha; int verifica; estrutura c; strt=&c; res = pthread_mutex_init(&mux, NULL); res = pthread_mutex_init(&muxNrComboio, NULL); res = pthread_mutex_init(&muxA_B, NULL); res = pthread_mutex_init(&muxB_C, NULL); res = pthread_mutex_init(&muxB_D, NULL); if(res!=0){ perror("Erro!\n"); return 0; } strt->numeroComboio=0; do{ printf("1-Viagem 1 (Cidade C - Cidade B - Cidade A)\n"); printf("2-Viagem 2 (Cidade A - Cidade B - Cidade D)\n"); printf("3-Sair\n"); printf("Escolha qual a opção que deseja:\n"); scanf ("%d",&escolha); if(escolha==3){ break; } tipoViagem=escolha; pthread_t thread; /* fim do preenchimento do vetor */ pthread_create(&thread, NULL, viagem, tipoViagem); strt->a=0; strt->b=0; strt->c=0; strt->d=0; }while(verifica!=0); pthread_mutex_destroy(&mux); pthread_mutex_destroy(&muxNrComboio); pthread_mutex_destroy(&muxA_B); pthread_mutex_destroy(&muxB_D); pthread_mutex_destroy(&muxB_C); FILE * f; f=fopen("output.txt", "w"); /*apenas para limpar o ficheiro ao sair do programa */ fclose(f); return 0; }
int main() { long int t, T; scanf("%ld",&T); for( t = 0 ; t < T ; t ++ ) { long int q = 0, Q = 0; // querry counter, number of querries // Get input scanf("%ld", &Q); accNumber* array = new accNumber[Q]; accNumber temp; int flag1, flag2, flag3, flag4, flag5, flag6; int num1, num3, num4, num5, num6; long int num2; flag1 = flag2 = flag3 = flag4 = flag5 = flag6 = false; // scan all querries scanf("%d%ld%d%d%d%d", &(temp.a), &(temp.b), &(temp.c)\ , &(temp.d), &(temp.e), &(temp.f)); array[q] = temp; num1 = temp.a; num2 = temp.b; num3 = temp.c; num4 = temp.d; num5 = temp.e; num6 = temp.f; for ( q = 1 ; q < Q ; q ++ ) { scanf("%d%ld%d%d%d%d", &(temp.a), &(temp.b), &(temp.c)\ , &(temp.d), &(temp.e), &(temp.f)); if (temp.a != num1) flag1 = true; if (temp.b != num2) flag2 = true; if (temp.c != num3) flag3 = true; if (temp.d != num4) flag4 = true; if (temp.e != num5) flag5 = true; if (temp.f != num6) flag6 = true; array[q] = temp; } if ( flag6 ) qsort(array, Q, sizeof(accNumber), & compare6); if ( flag5 ) qsort(array, Q, sizeof(accNumber), & compare5); if ( flag4 ) qsort(array, Q, sizeof(accNumber), & compare4); if ( flag3 ) qsort(array, Q, sizeof(accNumber), & compare3); if ( flag2 ) qsort(array, Q, sizeof(accNumber), & compare2); if ( flag1 ) qsort(array, Q, sizeof(accNumber), & compare1); for ( q = 0 ; q < Q ; q ++ ) { printf("%02d %08ld %04d %04d %04d %04d\n",\ array[q].a, array[q].b, array[q].c, array[q].d, array[q].e, array[q].f); } putchar('\n'); } return 0; }