Rel. la 0729 131 325
1549. Generate combinations
1550. There is a number of n elements. It is required to generate all the combinations
of n take by p.
1551. Example: n = 3 and p = 2
1552. It will display:
1553. 1 2
1554. 1 3
1555. 2 3
1556. #include
1557. int [20], n, p, k, as, ev;
1558. void init (int k, int st [])
1559. {st [k] = 0;}
1560. int successor (int k, int st [])
1561. {if (st [k]
1563. as = 1;
1564. }
1565. else as = 0;
1566. return as;
1567. }
1568. int valid (int k, int st [])
1569. {
1570. ev = 1;
1571. for (int i = 1; i
1573. ev = 0;
1574. return ev;
1575. }
1576. int solution (int k)
1577. {if (k == p)
1578. return 1;
1579. else return 0;}
1580. void typar ()
1581. {for (int i = 1; i <= p; i ++)
1582. cout << st [i];
1583. cout << endl;
1584. }
1585. void main ()
1586. {cin >> n; cin >> p;
1587. k = 1;
1588. init (k st);
1589. while (k> 0)
1590. {
1591. do {
1592. as= successor (K st);
1593. if (as)
1594. ev = valid (k, st);
1595. }
1596. while (! (! as || (as && ev)));
1597. if (as)
1598. if (solution (k))
1599. typar ();
1600. else
1601. {k ++;
1602. init (k st);
1603. }
1604. else k--;
1605. }
1606. return 0;}
1607. Problem solved:
1608. #include
using namespace std;
int main()
{ int n,i,v[20],n1=0,n2=0;
float S,ma;
cin>>n;
for(i=1;i<=n;i++)
cin>>v[i];
for(i=1;i<=n;i++)
if(v[i]==1)
v[i]=0;
for(i=1;i<=n;i++)
if(v[i]==0)
v[i]=1;
for(i=1;i<=n;i++)
if(v[i]==0)
n1++;
for(i=1;i<=n;i++)
if(v[i]==0)
n2++;
cout<
for(i=1;i<=n;i++)
S=S+v[i];
ma=S/n;
cout<
cout<
1609. what will be display?
#include
using namespace std;
int main()
{ int n,i,v[20],n1=0,n2=0,n3=0;
float S,ma;
cin>>n;
for(i=1;i<=n;i++)
cin>>v[i];
for(i=1;i<=n;i++)
if(v[i]==1)
v[i]=0;
for(i=1;i<=n;i++)
if(v[i]==0)
v[i]=1;
for(i=1;i<=n;i++)
if(v[i]==0)
n1++;
for(i=1;i<=n;i++)
if(v[i]==0)
n2++;
cout<
for(i=1;i<=n;i++)
S=S+v[i];
ma=S/n;
cout<
cout<
if(v[i]>v[i-1]&&v[i]>v[i+1])
n3++;
cout<
1612. what will be display?
1
Niciun comentariu:
Trimiteți un comentariu
Rețineți: Numai membrii acestui blog pot posta comentarii.