Skip to content

Instantly share code, notes, and snippets.

@shirohana
Created January 3, 2016 10:05
Show Gist options
  • Save shirohana/221966e477fdd1cd2ea3 to your computer and use it in GitHub Desktop.
Save shirohana/221966e477fdd1cd2ea3 to your computer and use it in GitHub Desktop.
TIOJ - problem 1004 - Use linked-list
// Problem source: http://tioj.infor.org/problems/1004
#include <iostream>
using namespace std;
typedef struct node {
int data;
node *next;
node(int _data) {
data = _data;
next = 0;
}
} node;
int main() {
int input;
cin >> input;
node *start = new node(0);
node *it = start;
for (int i = 1; i < input; ++i) {
node *temp = new node(i);
it->next = temp;
it = it->next;
}
it->next = start;
it = start;
for (int i = 1; i < input; ++i) {
it->next = it->next->next;
it = it->next;
}
cout << it->data + 1 << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment