Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node{
- node(int x = 0, node * y = NULL):num(x), next(y){
- num = x;
- next = y;
- };
- node(node const & copy)
- : num(copy.num), next(new node(*copy.next)){};
- int num;
- node * next;
- };
- int n;
- int main(){
- cin >> n;
- //здесь я просто создаю узлы, чтобы проверить
- node * head = new node();
- node * x = head;
- for (int i = 0; i < n - 1; ++i){
- node * y = new node(i, x);
- x = y;
- }
- head->next = x;
- node * curr = head;
- for (int i = 0; i < n + 1; ++i){ // проходимся n + 1 раз и мы в цикле
- curr = curr->next;
- }
- node * beg = curr; // фиксируем начало цикла
- int k = 1;
- curr = curr->next;
- while (beg != curr){ // пока не пришли туда же бегаем по циклу
- curr = curr->next;
- ++k;
- }
- cout << k; //профит
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement