You are on page 1of 7

Probleme coada

1.
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
char nume[20], profesie[20];
int salariu,n;
struct nod
{
char nume[20],profesie[20];
int salariu;
nod *urm;
} *p, *q, *u;
void init (nod *&p, nod *&u)
{
p=NULL;
u=NULL;
}
void adaugare_element_prim (nod *&p, nod *&u)
{
p=new nod;
strcpy (p->nume,nume);
strcpy (p->profesie, profesie);
p->salariu = salariu;
p->urm = NULL;
u=p;
}
void adaugare_element (nod *&u)
{
q=new nod;
strcpy (q->nume,nume);
strcpy (q->profesie, profesie);
q->salariu = salariu;
q->urm=NULL;
u->urm=q;
u=q;
}
void afisare (nod *p)
{
q=p;
while (q)
{
g<<q->nume<<" "<<q->profesie<<" "<<q->salariu<<endl;

q=q->urm;
}
}
int main ()
{
f>>n;
f.get();
f>>nume>>profesie>>salariu;
adaugare_element_prim(p,u);
for (int i=2;i<=n;i++)
{
f>>nume>>profesie>>salariu;
adaugare_element (u);
}
p=p->urm;
p->salariu+=20000;
afisare(p);
}
2.
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int n,x;
struct nod
{
int x;
nod *urm;
} *p, *q, *u;
void init (nod *&p, nod *&u)
{
p=NULL;
u=NULL;
}
void adaugare_element_prim (nod *&p, nod *&u)
{
p=new nod;
p->x=x;
p->urm = NULL;
u=p;
}
void adaugare_element (nod *&u)
{
q=new nod;

q->x=x;
q->urm=NULL;
u->urm=q;
u=q;
}
int prim (int x)
{
int i;
for (i=1;i<=x/2;i++)
if (x%i==0) return 0;
return 1;
}
void afisare (nod *p)
{
while (prim(p->x)==0)
p=p->urm;
q=p;
while (q)
{
g<<q->x<<endl;
q=q->urm;
}
}
int main ()
{
f>>n;
f>>x;
adaugare_element_prim(p,u);
for (int i=2;i<=n;i++)
{
f>>x;
adaugare_element (u);
}
afisare(p);
}
PROBLEME RECAPITULATIVE
1.
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
char nr[100];
int frq[10],i;
int main ()
{

f.get(nr,100);
g<<nr<<endl;
for (i=strlen(nr)-1;i>=0;i--)
{
g<<nr[i];
frq[nr[i]-'0']++;
}
g<<endl;
for (i=9;i>=0;i--)
while (frq[i])
{
g<<i;
frq[i]--;
}
}
4.
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int n,x;
struct nod
{
int x;
nod *urm;
} *p, *q, *u;
void init (nod *&p, nod *&u)
{
p=NULL;
u=NULL;
}
void adaugare_element_prim (nod *&p, nod *&u)
{
p=new nod;
p->x=x;
p->urm = NULL;
u=p;
}
void adaugare_element (nod *&u)
{
q=new nod;
q->x=x;
q->urm=NULL;
u->urm=q;

u=q;
}
void afisare (nod *p)
{
q=p; int OK=1;
int r=q->urm->x-q->x;
q=q->urm;
while (q->urm){
if (r != (q->urm)->x - q->x) OK=0;
q=q->urm;}
if (OK)
g<<"progr";
else g<<"nu e progr";
}
int main ()
{
f>>n;
f>>x;
adaugare_element_prim(p,u);
for (int i=2;i<=n;i++)
{
f>>x;
adaugare_element (u);
}
afisare(p);
}
Stiva
1. #include <fstream>
#include <string.h>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
char a[100][100], x[100];
int k=0,i;
int main ()
{
while (!f.eof())
{
f.get (x,100);
char *p;
p=strtok(x,"*");
while(p)
{
strcpy(a[++k],p);
p=strtok(NULL,"*");
}

f.get();
}
for (i=1;i<=k;i++)
g<<a[i]<<" ";
g<<"blabla";
}
20.
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
struct nod
{
int x;
nod *urm;
} *p, *u, *q, *m;
int x;
void init (nod *&p, nod *&u)
{
p=NULL;
u=NULL;
}
void adaugare_prim_element (nod *&p, nod *&u)
{
p=new nod;
p->x=x;
p->urm=NULL;
u=p;
}
void adaugare_element (nod *&u)
{
q=new nod;
q->x=x;
q->urm=NULL;
u->urm=q;
u=q;
}
void afisare (nod *p)
{
q=p;
int c=1,maxim=0;
while (q->urm)
{
if (q->x<q->urm->x)

c++;
else { if (maxim<c) maxim=c; c=1; }
q=q->urm;
}
g<<maxim;
}
int main ()
{
f>>x;
init (p,u);
adaugare_prim_element (p,u);
while (f>>x)
adaugare_element (u);
afisare (p);
}