1.#include<iostream>
using namespace std;
float a[100];
int n, i;
void prelucrare()
{for(i=1;i<=n;i++)
if((int)a[i]==a[i])
cout<<a[i]<<' '<<a[i]<<' ';
else
cout<<(int)a[i]+1<<' '<<(int)a[i]<<' ';
}
int main()
{cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
prelucrare();
return 0;
}
2.#include<iostream>
using namespace std;
int m,n,a[100],i,j;
int main()
{
cin>>m>>n;
for(i=1;i<=m+n;i++)
cin>>a[i];
for(i=1;i<=m;i++)
for(j=m+1;j<=n+m;j++)
if(a[i]==a[j])
cout<<a[i]<<' ';
return 0;
}
3.#include<iostream>
using namespace std;
int a[100], n,i,k;
int main()
{
cout<<"n=";cin>>n;
k=1;
for(i=1;i<=n/2;i++)
{a[i]=k;a[n-i+1]=++k;k++;
}
if(n%2!=0)
a[n/2+1]=k;
for(i=1;i<=n;i++)
cout<<a[i]<<' ';
return 0;
}
4.#include<iostream>
using namespace std;
int main()
{
int n,k,x,ok,i;
cin>>n;
k=n;x=2;
while(k)
{ok=1;
for(i=2;i<=x/2;i++)
if(x%i==0)
ok=0;
if(ok)
{cout<<x<<' ';
k--;}
x++;
}
return 0;
}
5.//n natural, nenul, max 9cifre; k natural, nenul, a.i. 1*2*3*...*k cat mai apropit de n
#include<iostream>
#include<math.h>
using namespace std;
int main()
{int i=1,p=1,n;
cin>>n;
do
{p*=i;i++;}while(p<n);
i=i-1;
if(abs(n-p)<abs(n-(p/i)))
cout<<i;
else
cout<<(i-1);
return 0;
}
6.#include<iostream>
using namespace std;
int v[100],n,i,j;
void citire()
{cin>>n;
for(i=1;i<=n;i++)
cin>>v[i];
}
void ordonare()
{int aux;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if(v[i]>v[j])
{aux=v[i];
v[i]=v[j];
v[j]=aux;
}
}
int main()
{int k=1;
citire();
ordonare();
cout<<v[1]<<' ';
for(i=2;i<=n;i++)
if(v[i]!=v[i-1])
{
cout<<v[i]<<' ';
k++;
if(k==5)
{cout<<'\n';k=0;}
}
return 0;
}
7.#include<iostream>
using namespace std;
int a[30][30],n,k,i,j;
int main()
{
cin>>n;
if(n<2 || n>30)
cout<<"n incorect!";
else
{
for(i=1;i<=n;i++)
{
k=i;
for(j=1;j<(n-i+1);j++)
a[i][j]=k++;
for(j=(n-i+1);j<=n;j++)
a[i][j]=k--;
}
}
for(i=1;i<=n;i++)
{for(j=1;j<=n;j++)
cout<<a[i][j]<<' ';
cout<<endl;}
return 0;
}
8.#include<iostream>
using namespace std;
int a[100][100],n,m,i,j,p,suma;
int maxim(int k)
{int maximum=a[k][1];
for(i=2;i<=n;i++)
if(a[k][i]>maximum)
maximum=a[k][i];
return maximum;
}
int main()
{cin>>m>>n;
for(i=i;i<=m;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
for(i=1;i<=m;i++)
{
p=maxim(i);
cout<<p<<endl;suma+=p;
}
cout<<suma<<'\n';
return 0;
}
9.#include<iostream>
using namespace std;
int a[100][100],m,n,i,j;
int main()
{
cin>>m>>n;
if(2>m || m>10 || 2>n || n>10)
cout<<"date eronate!";
else
{
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(i<j)
a[i][j]=i*10+j;
else
a[i][j]=j*10+i;
}
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
cout<<a[i][j]<<' ';
cout<<endl;
}
return 0;
}
10.#include<iostream>
#include<string.h>
using namespace std;
char cuv[20];int i;
int main()
{cin>>cuv;
for(i=0;i<strlen(cuv);i++)
if(strchr("aeiou", cuv[i])!=0)
{strcpy(cuv+i,cuv+i+1);
cout<<cuv<<endl;
}
return 0;
}
11.#include<iostream>
#include<string.h>
using namespace std;
int n;
char cuv[21];
int main()
{
cin>>cuv;
n=strlen(cuv);
if(n==1 || n==2)
cout<<"Cuvant vid";
else
{
if(n%2==1)
strcpy(cuv+n/2, cuv+n/2+1);
else
strcpy(cuv+n/2-1, cuv+n/2);
}
cout<<cuv;
return 0;
}
12.#include<iostream>
using namespace std;
int n, a[20][20],i,j;
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(j==i || j==n-i+1)
a[i][j]=1;
else
if(j<(n-i+1) && i<j || i>j && j>(n-i+1))
a[i][j]=2;
else
//if(i<j && j>(n-i+1) || i<j &&j>(n-i+1))
a[i][j]=3;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<a[i][j]<<' ';
cout<<endl;}
return 0;
}
13.#include<iostream>
#include<string.h>
using namespace std;
char cuv[31],cuv1[31];
int n,i;
int main()
{
cin>>cuv;
n=strlen(cuv);strcpy(cuv1,cuv);
for(i=0;i<n;i++)
{cout<<cuv<<' ';
cuv[strlen(cuv)-1]='\0';
cout<<cuv1+i<<endl;
}
return 0;
}
14.#include<iostream>
#include<string.h>
using namespace std;
char c1[31],c2[31],*p;
int i,ok=1;
int main()
{
cin.get(c1,30);
cin.get();
cin.get(c2,30);
cin.get();
if(strlen(c1)!=strlen(c2))
cout<<"NU";
else
{
for(i=0;i<strlen(c1)&& ok;i++)
{p=strchr(c2,c1[0]);
if(p==0)
ok=0;
else
{strcpy(p,p+1);
strcpy(c1,c1+1);
}
}
if(ok)
cout<<"DA";
else
cout<<"NU";
}
return 0;
}
15.#include<iostream>
using namespace std;
int n,i=1,a[8],k,k1,j,p=1;
int main()
{cin>>n;
while(n)
{
a[++i]=n%10;
n=n/10;
}
k=i;
k1=i;
while(k1)
{if(a[k1])
{for(i=k1;i>1;i--)
cout<<a[i];
cout<<endl;
}
k1--;
}
while(p<k)
{
for(i=k;i>p;i--)
cout<<a[i];
cout<<endl;
p++;
}
return 0;
}
16.#include<iostream>
#include<string.h>
using namespace std;
char a[20][20];
int n,i,j;
int main()
{cin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>a[i];
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if(strstr(a[i],a[j])||strstr(a[j],a[i]))
cout<<a[i]<<' '<<a[j]<<endl;
return 0;
}
17.#include<iostream>
using namespace std;
int main()
{
int m,n,a[100][100],i,j,k,l,p,s=0;
cin>>m>>n;
if(n<=100 && m<=100)
{for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cin>>i>>j;
cin>>l>>k;
for(p=j;p<=l;p++)
s=s+a[i][p]+a[k][p];
for(p=i+1;p<k;p++)
s=s+a[p][j]+a[p][l];
cout<<s;
}
else
cout<<"date gresite";
return 0;
}
18.#include<iostream>
using namespace std;
long nr;
int i,k,p=1,aux;
int main()
{cin>>nr;
aux=nr;
i=1;
do
{
p=p*10;
aux=aux/10;
i++;
}while(aux);
k=i-1;p=p/10;
for(i=1;i<=k;i++)
{
cout<<nr<<' ';
nr=nr%p*10+nr/p;
}
return 0;
}
19.#include<iostream>
#include<string.h>
using namespace std;
int c[26],i,l;
char sir[101];
void citire()
{cin.getline(sir,101);
l=strlen(sir);
for(i=0;i<l;i++)
if(sir[i]>='a' && sir[i]<='z')
c[sir[i]-'a']++;
}
int main()
{citire();
citire();
int ok=1;
for(i=0;i<=26;i++)
if(!c[i])
{
cout<<i+'a'<<' ';
ok=0;
}
if(ok)
cout<<"toate literele sunt in string";
return 0;
}
Pages
Subscribe to:
Posts (Atom)
0