Bercean+Ioan

__** ordonare descrescatoare recursiva: **__
using namespace std; int a[100],n; void desc(int i, int j){ int aux; if(a[j]>a[i]){ aux=a[j]; a[j]=a[i]; a[i]=aux;} if(j==n) return ; j=j+1; desc(i,j); if(i==n-1) return; i=i+1; desc(i,j); } int main{ int i; cout<<"n="; cin>>n; cout<<"a[i]="; for(i=0;i>a[i]; cout<>n; for(i=1;i<=n;i++) f>>x[i]; y[n]=1; for(j=n-1;j>0;j--){ max=0; for(i=j+1;i<=n;i++) if(x[j]max) max=y[i]; y[j]=max+1; } max=0; for(i=1;i<=n;i++) if(y[i]>max){ max=y[i]; poz=i;} cout<<"l. max.= "<<max; cout<<endl<<"x si y"<<endl; for(i=1;i<=n;i++) cout<<setw(3)<<x[i]; cout<<endl; for(i=1;i<=n;i++) cout<<setw(3)<<y[i]; u=max; for(i=1;i<=n;i++) if(y[i]==u && aux<x[i]){ u--; cout<<endl<<x[i]<<" "<<y[i]; aux=x[i]; }

return 0; }

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

** algoritm fill(cu imaginea): **
using namespace std; int a[100][100],n,m; int size; void fill(int i,int j) { if(a[i][j]==1) { a[i][j]=2; //fiecarei element din regiune ii corespunde numarul zonei// //size++;// ///*verificam daca elementele alaturate pot apartine aceiasi regiuni si daca nu au fost// //inca marcate*/// //fill(i-1,j);// //fill(i+1,j);// //fill(i,j-1);// //fill(i,j+1);// //fill(i-1,j-1);// //fill(i+1,j+1);// //fill(i+1,j-1);// //fill(i-1,j+1);// //}// //}//
 * 1) include
 * 2) include
 * 3) include
 * 4) include

//int main// //{// //int i,j,ok=1;// //ifstream f("date.in");// //f>>n;// //for(i=1;i<=n;i++)// //for(j=1;j<=n;j++)// //f>>a[i][j];// //for(i=1;i<=n;i++)// //for(j=1;j<=n;j++)// //if(a[i][j]==1){// //size=0;//numarul de elemente dintr-o regiune este initial 0 fill(i,j); i=j=n+1; } for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(a[i][j]==1) ok=0; cout<>n>>m>>is>>js>>xf>>yf; int i,j; for(i=1;i<=n;i++) for(j=1;j<=m;j++) f>>L[i][j]; } void afisare { int i,j; nrsol++; cout<<"Sol nr: "<=1 && inou<=n && jnou>=1 && jnou<=m) if(L[inou][jnou]==0 && sol[inou][jnou]==0) { sol[inou][jnou]=pas; if(inou==xf && jnou==yf) afisare; else traseu(inou,jnou,pas+1); sol[inou][jnou]=0; } } } int main { citire; sol[is][js]=1; traseu(is,js,2); return 0; }
 * 1) include
 * 2) include
 * 3) include

using namespace std; int cif(int a, int b){ int s=0; while(a>0){ if(a%10==b) s++; a=a/10;} return s; } int main{ int a,b,f[10]={0},i,ok; cout<<"a="; cin>>a; //cout<<"b=";// cin>>b; //cout<1) cout<<"NU";// //else{...}//
 * 1) include

//}//

//#include// //#include// //char a[]=" BORK BORK BORK!",s[100];// //void BORK(char s[])// //{strcat(s,a);}// //void f10(char s[],char c1,char c2)// //{char *p;// //while(p=strchr(s,c1))// //s[p-s]=c2;// //}// //void f4(char s[]){// //int i,n=strlen(s);// //for(i=0;i<n;i++)// //if(s[i]=='A' && s[i-1]!=' ' && s[i+1]!='.')s[i]='E';// //}// //void f2(char s[],char t[],char u[])// //{int a=strlen(t);// //char v[100],*p;// //v[0]=NULL;// //while(p=strstr(s,t))// //{strcpy(v,s);// //v[p-s]='\0';// //strcat(v,u);// //strcat(v,p+a);// //strcpy(s,v);// //v[0]=NULL;}// //}// //void f69(char s[]){// //int i,k=0,n=strlen(s); char a[100];// //for(i=0;i<=n;i++){// //if(s[i]=='E' && (s[i+1]==' ' || s[i+1]=='.')){a[k]='E';// //k++;// //a[k]='-';// //k++;// //a[k]='A';}// //else a[k]=s[i];// //k++;// //}// //strcpy(s,a);// //}// //void f7(char s[])// inlocuim F cu FF { char a[100]; int i,k=0; for(i=0;i<=strlen(s);i++){ if(s[i]!='F') a[k]=s[i]; else{ a[k]='F'; k++; a[k]='F'; } k++;} strcpy(s,a); } void f5(char s[]){ int i,n=strlen(s),k=1; char a[100]; a[0]=s[0]; for(i=1;i<=n;i++){ if(s[i]=='I' && s[i-1]!=' '){ a[k]='E'; k++; a[k]='E'; while(s[i]!=' '){ k++; i++; a[k]=s[i]; } k++; } else{ a[k]=s[i]; k++;} } strcpy(s,a); } int main { ifstream f("date.in"); ofstream g("date.out"); int n,i; f>>n; f.get; for(i=0;ib) a=a-b; else b=b-a; return a; } int main{ int i,n,a; cin>>n; fractie v[10]; for(i=0;i<2;i++){ cout<<"v["<>v[i].num; cout<<"v["<>v[i].nr; } cout<dr) return -1; m=(st+dr)/2; if(a[m]>x){ cout<<" stanga "<>n; for(i=0;i>x; binar(x,0,n-1); return 0; }
 * 1) include

tema using namespace std; int x[100],n,i=0; void s(int S, int dr, int st){ int a,m,b; if(x[i]<S/2 && a!=x[i+1]){ a=x[i]; i++; b=S-a;} if(st<=dr){ m=(dr+st)/2; if(x[m]==b) s(S,st,m-1); else cout<<x[m]<<" "<<a;} } int main{ int i,j,aux,S; cin>>S>>n; cout<<endl; for(i=0;i<n;i++) cin>>x[i]; for(i=0;i<n;i++) for(j=i;j<n;j++) if(x[i]>x[j]){aux=x[i]; x[i]=x[j]; x[j]=aux; } for(i=0;i<n;i++) if(x[i]>S) n=i-1; s(S,0,n-1); return 0; }
 * 1) include

tema:10,12,13,14;

using namespace std; int re(int n, int k){ cout<<n<<" "<<k<<endl; if(k==0) return 1; else return (double)n/k*re(n-1,k-1); } int main{ int n,k; cin>>n>>k; cout<<"combinari de "<<n<<" luate cate "<<k<<" = "<<re(n,k); return 0;} = = = = = = = = =__= = = =25.03.2011= using namespace std; int re(int a, int b, int &c){ cout<<a<<" "; if(a<b) return a; else {c++; return re(a-b,b,c); } } int des(int n, int x){ if(n<x) return 0; else {cout<<n<<" + "<<x<<endl; des(n-1,x+1);} } int main{ int a,b,c=0,n,x=0; cin>>a>>b; cout<<a<<" / "<<b<<" = "<<c<<" rest "<<re(a,b,c); cin>>n; des(n,x); return 0;}
 * 1) include
 * 1) include

= = = = = = = = =_= = __10 A__ = Tema

Se da un vector cu n elemente numere intregi. Sa se transforme vectorul, aplicand urmatoarea regula: daca 2 elemente alaturate sunt egale, unul din acestea se elimina. Sa se afiseze toate transformarile vectorului. = = =24.02.2011= using namespace std; int a[10][10],n; int sumaj(int j){ int s=0,i; for(i=0;i<n;i++) s=s+a[i][j]; return s;} void citire{ int i,j; cout<<"dati n:"; cin>>n; for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>a[i][j]; } void inversare(int i, int j){ int k,aux; for(k=0;k<n;k++){ aux=a[i][k]; a[i][k]=a[j][k]; a[j][k]=aux; } } void afisare{ int i,j; for(i=0;i<n;i++){ cout<<endl; for(j=0;j<n;j++) cout<<a[i][j]<<" "; } cout<<endl<<endl;} void dg{ int i,j; cout<<"el. de pe principala: "; for(i=0;i<n;i++){ cout<<endl; for(j=0;j<n;j++) if(i==j)cout<<a[i][j]; else cout<<" "; }} int suma(int i){ int j,s=0; for(j=0;j<n;j++) s=s+a[i][j]; return s;} int main{ int i,j; citire; afisare; dg; cout<<endl<<"dati i"; cin>>i;cout<<suma(i); cout<<endl<<"dati j"; cin>>j; cout<<"suma de pe coloana j este: "<<sumaj(j); inversare(i,j); afisare; return 0; } = = = = = Problema 18.02.2011: =
 * 1) include

=
<span style="color: #222222; font-family: Arial; font-size: 8pt; font-weight: normal; line-height: 14.25pt; margin: 0in;">sa se scrie o functie care primeste ca parametruun nr nat n si returneaza valoarea 1 daca nr n are toate cifrele distincte si valoarea 0 in caz contrar.Sa se apeleze functia pt a verifica toate elemtelele unui tablou d enr intregi ======

using namespace std; int nr(int n){ int i,m,ok=1,j; m=n; for(i=1;i<n;i=i*10) for(j=i*10;j<n;j=j*10) if(n/i%10==n/j%10) ok=0; return ok; } int main{ int a[100],n,i,m; cout<<"dati n: "; cin>>n; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n;i++){ m=a[i]; cout<<nr(m)<<endl; } return 0; }
 * 1) include

problema 1:

problema clasa: using namespace std; int randx(int x){ return rand%x+1;} void aruncare(int &s, int &nr, int &ok){ int ar[7]={0},x,i; s=0; nr=1; x=randx(6); cout<<"aruncarile: "<<x; ar[x]++; s=s+x; ok=1; while(x!=6){ x=randx(6); cout<<x; s=s+x; nr++; ar[x]++;} for(i=1;i<7;i++) if(ar[i]==0) ok=0; cout<<endl;} int main{ int s1,s2,nr1,nr2,ok1,ok2; srand(time(NULL)); aruncare(s1,nr1,ok1); aruncare(s2,nr2,ok2); if(ok1==0 && ok2==0) cout<<endl<<"nu castiga nici unu"; else if(ok1==1 && ok2==0) cout<<endl<<"primul castiga (a aruncat toate fetele)"; else if(ok1==0 && ok2==1) cout<<endl<<"al 2-lea castiga (a aruncat toate fetele)"; else if(ok1==1 && ok2==1 && s1>s2) cout<<endl<<"primul castiga(are suma mai mare)"; else if(ok1==1 && ok2==1 && s1<s2) cout<<endl<<"al 2-lea castiga(are suma mai mare)"; else if(ok1==0 && ok2==1) cout<<endl<<"al 2-lea castiga (a aruncat toate fetele)"; else if(nr2>nr1) cout<<endl<<"primul castiga(a dat de mai putine ori)"; else if(nr2<nr1) cout<<endl<<"al 2-lea castiga(a dat de mai putine ori)"; else if(nr1==nr2)cout<<endl<<"sunt la egalitate"; cout<<endl; }
 * 1) include

-functie care numara vocalele dintr-un sir de caractere:
 * tema** 14.02.2011

int vocale(char a[]) { int i,nrv=0; char voc[]="aeiou"; for(i=0;i<strlen(a);i++) if(strchr(voc,a[i])!=NULL) nrv++; return nrv; }

-functie care sa verifice daca un numar este palindrom:

int palindrom(char a[]) { int i=0,j=strlen(a)-1,ok=1; while(i<=j && j>=i) { if(a[i]!=a[j]) ok=0; i++; j++; } if(ok==1) return 1; else return 0; }

-functie care returneaza suma tuturor cifrelor care apar intr-un sir de caractere:

int cifre(char a[]) { int i; char s=0; for(i=0;i<strlen(a);i++) if(isdigit(a[i])!=NULL) s=s+a[i]; return s; }

Tema 16.02.2011 Problema 7

using namespace std; void inversare(double a, double &a1){ double x=a-(int)a; //in x avem partea fractionara;// //double y=int(a);// //int f=0;// //while(x!=(int)x){// //x=x*10;// //cout<<x<<" "<<int(x)<<", ";// //f++;// //if(f==6) break;}// //while((int)y!=0)// //y=y/10;// //a1=x+y;}// //double maxim(double x, double y)// //{if(x>y)// //return x;// //else return y;}// //void maxima(double a, double b, double &c){// //double a1,b1;// //inversare(a,a1);// //inversare(b,b1);// //c=maxim(maxim(a,a1),maxim(b,b1));// calculam max dintre a1,b1,a si b; } int main{ double a,b,c; cout<<"dati 2 nr reale: "; cin>>a>>b; maxima(a,b,c); cout<<"maximul dupa inversari este: "<<c; return 0; }-de corectat
 * 1) include

using namespace std; int citire(int a[], int n){ int i; for(i=0;i<n;i++) cin>>a[i]; } int afisare(int a[],int n){ int i; for(i=0;i<n;i++) cout<<a[i]; } void m(int a[],int n ,int &max, int &min){ int i; for(i=0;i<n;i++){ if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; } } int nr(int a[],int n,int k){ int i,s=0; for(i=0;i<n;i++) if(a[i]==k)s++; return s; } int elimin(int a[],int &n, int t){ int i; for(i=t;i<n;i++) a[i]=a[i+1]; n--; } int main{ int a[100],n,max,min,k,t; cout<<"dati n"; cin>>n; citire(a,n); max=a[0]; min=a[0]; m(a,n,max,min); cout<<"maximul este "<<max<<" iar minimul "<<min<<endl; cout<<"dati k"; cin>>k; nr(a,n,k); cout<<"numarul "<<k<<" apare de "<<nr(a,n,k)<<" ori"<<endl; cout<<"dati t "; cin>>t; elimin(a,n,t); afisare(a,n); return 0; }
 * 1) include