Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int e=0;
- int hanoi_towers(int a, int b, int c, int d) //a-число колец, b-начальное положение колец(1-3),c-конечное положение колец(1-3), d - промежуточный колышек(1-3)
- {
- if (a!=0)
- {
- hanoi_towers(a-1, b, d, c);
- cout«b«" -> "«c«endl;
- e++;
- hanoi_towers(a-1, d, c, b);
- }
- return e;
- }
- int main()
- {
- setlocale(LC_ALL,"rus");
- int a,b,c,d,f=0,e=0,i;
- cout«"Номер первого столбика:"«endl;
- cin»a;
- cout«"Номер конечного столбика:"«endl;
- cin»b;
- cout«"Номер промежуточного столбика:"«endl;
- cin»c;
- cout«"Количество дисков:"«endl;
- cin»d;
- f=hanoi_towers(d, a, b, c);
- cout«endl«"Всего обменов "«f;
- return 0;
- }
- #include <iostream>
- using namespace std;
- int main()
- {
- int a,b;
- cin»a»b;
- while(a>0 && b>0)
- if(a>b)
- a%=b;
- else
- b%=a;
- cout«a+b;
- return 0;
- }
- Это четвёртое
- #include <iostream>
- using namespace std;
- int main()
- {
- int a,b,k=0,c,n,i;
- cin»n;
- int g[n];
- for (i=0; i<n; i++)
- cin»g[i];
- for (i=0; i<n+1; i++)
- if (g[i]>g[i+1]) {b=g[i+1]; g[i+1]=g[i]; g[i]=b; i=-1;}
- a=g[0];
- b=g[1];
- while(a>0 && b>0)
- if(a>b)
- {a%=b; k++;}
- else
- {b%=a; k++;}
- c=a+b;
- for (i=2; i<n-1; i++){
- a=g[i];
- b=g[i+1];
- while (a>0 && b>0)
- if(a>b)
- {a%=b; k++;}
- else
- {b%=a; k++;}
- if (c%(a+b)==0) c=a+b;
- else
- if ((a+b)%c==0) {c++; c--;}
- else { c=0;
- break;}
- }
- if (c!=0) cout«c«' '«k;
- else cout«"NO";
- return 0;
- }
- //6 126 36 45 90 27 63
- Это пятое
- Тест возьмите другой
- #include <iostream>
- using namespace std;
- int main()
- {
- int a,b,c,k,n;
- cin»n;
- k=0;
- for (a=0; a<n; a++)
- for (b=0; b<n; b++)
- for (c=0; c<n; c++)
- k++;
- cout«k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement