rezolvare in c++ va rog
Răspunsuri la întrebare
#include <iostream>
using namespace std;
//a->1, e->5, i->9
int cif_distincte(int x, int n, int c[])
{
int f[10]={0,0,0,0,0,0,0,0,0,0};
for(int i=n-1;i>=0;i--)
{
c[i]=x%10;
f[c[i]]++;
x=x/10;
}
for(int cif=1;cif<=n;cif++)
if(f[cif]!=1)
return 0;
return 1;
}
int ok_voc(int c[],int n)
{
for(int i=0;i<=n-2;i++)
if(c[i]==1 && c[i+1]==5 || c[i]==5 && c[i+1]==1 ||
c[i]==1 && c[i+1]==9 || c[i]==9 && c[i+1]==1 ||
c[i]==5 && c[i+1]==9 || c[i]==9 && c[i+1]==5)
return 0;
return 1;
}
int main()
{
int n,i,nmin=0,nmax=0, c[10];
char s[10];
cin>>n;
for(i=1;i<=n;i++)
nmin=nmin*10+i;
for(i=n;i>=1;i--)
nmax=nmax*10+i;
for(i=nmin;i<=nmax;i++)
if (cif_distincte(i, n, c) && ok_voc(c,n))
{
for(int j=0;j<n;j++)
cout<<(char)('a'+c[j]-1);
cout<<endl;
}
}
prog.cpp:41:12: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(c[i]==1 && c[i+1]==5 || c[i]==5 && c[i+1]==1 ||
^
prog.cpp:43:9: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
c[i]==1 && c[i+1]==9 || c[i]==9 && c[i+1]==1 ||
^
prog.cpp:43:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
c[i]==1 && c[i+1]==9 || c[i]==9 && c[i+1]==1 ||
^
c[i]==5 && c[i+1]==9 || c[i]==9 && c[i+1]==5)
^
prog.cpp:45:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
c[i]==5 && c[i+1]==9 || c[i]==9 && c[i+1]==5)
^
prog.cpp: In function 'int main()':
prog.cpp:59:6: warning: unused variable 's' [-Wunused-variable]
char s[10];
^
Citește mai multe pe Brainly.ro - https://brainly.ro/tema/5231951#readmore
1 0.3770 25
2 2.3718 Limită de timp depășită
3 2.3710 Limită de timp depășită
4 1.1350 25