Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Problema 1

#include <iostream>
using namespace std;
int main()
{
int a[10][10],n, i, j, x;
cin>>n;
for(j=1, j<=n, j++)
{cin>>x;
a[1][j] = x;}
for(i=2; i<=n; i++)
{
a[i][1] = a[i-1][n];
for (j=2; j<=n; j++)
a[i][j] = a[i-1][j-1];
}
for(i=1; i<=n;i++)
{for(j=1; j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
Problema 2

#include <iostream>

#include <fstream>

using namespace std;

ifstream f("secventaincadrata.in");

ofstream g("secventaincadrata.out");

int cif, poz[10], lung[10], c, lungmax;

int main()

   while (f>>cif)

   {

       ++c;

       if (poz[cif]==0) { poz[cif]=c; lung[cif]=1; }

       else lung[cif]=c-poz[cif]+1;

   }

 for (cif=0; cif<10; ++cif)

       if (lung[cif]>lungmax) lungmax=lung[cif];

   g << lungmax << "\n";

   for (cif=0; cif<10; ++cif)

       if (lung[cif]==lungmax) g << cif << " ";

}
Problema 3
#include <iostream>
#include <fstream>
using namespace std;

int aparitii[900];

int main(){
int x,i,sw=0;
ifstream is("bac.in");
while(1){
is>>x;
//sfarsitul fisierului atins, oprim bucla
if(is.eof()) {
break;
}
//numarul este mai mic decat 100, nu ne intereseaza, reia bucla
if(x<100){
continue;
}
else if(x<1000){
if(aparitii[x-100]==0||aparitii[x-100]==2)
aparitii[x-100]+=1;
}
else{

while(x>100){
if(aparitii[x%1000-100]==0||aparitii[x%1000-100]==1)
aparitii[x%1000-100]+=2;
x=x/10;
}
   }   
}
for(i=0;i<900;i++){
if(aparitii[i]==3){
cout<<i+100<<endl;
sw=1;
}

}
if(sw==0){
cout<<"Nu exista";
}

return 0;

You might also like