//Tanzila Islam //Southeast University //mail : tanzilamohita@gmail.com #include <iostream> using namespace std; const int MAX_SIZE = 10000; class Stack { private: string array[MAX_SIZE]; int top; public: Stack() { top = 0; } void push(string x) { array[top] = x; top++; } string pop() { top--; return array[top]; } string peek() { return array[top - 1]; } bool isEmpty() { if (top == 0) return true; else return false; } }; int main() { int t; cin >> t; for(int i = 1; i<=t;i++){ cout << "Case " <<i <<":" << endl; Stack FORWARD, BACK; string s; string recenturl = "http://www.lightoj.com/"; while( cin >> s){ if( s == "QUIT"){ break; } else if( s == "VISIT"){ string url; cin >> url; BACK.push(recenturl); recenturl = url; while( FORWARD.isEmpty() == false) { FORWARD.pop(); } cout << recenturl << endl; } else if ( s == "FORWARD" ){ if( FORWARD.isEmpty() ){ cout << "Ignored" << endl; continue; } BACK.push(recenturl); recenturl = FORWARD.pop(); cout << recenturl << endl; } else { if( BACK.isEmpty() ){ cout << "Ignored" << endl; continue; } FORWARD.push(recenturl); recenturl = BACK.pop(); cout << recenturl << endl; } } } return 0; }
Showing posts with label LIGHT OJ. Show all posts
Showing posts with label LIGHT OJ. Show all posts
Saturday, 19 September 2015
LightOJ 1113 – Discover the Web_Solution
LightOJ 1023 – Discovering Permutations_Solution
// Tanzila Islam // Southeast University // mail : tanzilamohita@gmail.com #include <cstdio> #include <iostream> #include <string> using namespace std; int N, K; void recur(int length,int used[], string str){ if( K == 0 ) return; //prunning extra branches if( length == N ){ cout << str << endl; K--; return; } for(int i = 0; i < N; i++){ if(!used[i]){ string temp = str; temp += (char)(i+'A'); used[i] = 1; recur(length+1, used, temp); used[i] = 0; } } } int main(){ int T; cin >> T; for(int c = 1; c <= T; c++){ cin >> N >> K; int used[28]; for(int j = 0; j < N; j++) used[j] = 0; cout << "Case " << c << ":" << endl; recur(0,used,""); } }
Friday, 26 June 2015
LightOJ 1023 – Discovering Permutations_Solution
//Tanzila Islam //Southeast University //mail : tanzilamohita@gmail.com #include <cstdio> #include <iostream> #include <string> using namespace std; int N, K; void recur(int length,int used[], string str){ if( K == 0 ) return; //prunning extra branches if( length == N ){ cout << str << endl; K--; return; } for(int i = 0; i < N; i++){ if(!used[i]){ string temp = str; temp += (char)(i+'A'); used[i] = 1; recur(length+1, used, temp); used[i] = 0; } } } int main(){ int T; cin >> T; for(int c = 1; c <= T; c++){ cin >> N >> K; int used[28]; for(int j = 0; j < N; j++) used[j] = 0; cout << "Case " << c << ":" << endl; recur(0,used,""); } }
LightOJ 1001 – Opposite Task_Solution
//Tanzila Islam //Southeast University //mail : tanzilamohita@gmail.com #include <iostream> using namespace std; int main() { int t; cin >> t; for (int i = 1 ; i <= t; i++) { int n1, n2, n3; cin >> n1; n2 = n1 / 2; n3 = n1 - n2; cout << n2 << " " << n3 << endl; } return 0; }
LIGHT OJ – 1000 ( Greetings from LightOJ )_Solution
//Tanzila Islam //Southeast University //mail : tanzilamohita@gmail.com #include <iostream> using namespace std; int main() { int t; cin >> t; for (int i = 1 ; i <= t; i++) { int n1, n2, n3; cin >> n1 >> n2; n3 = n1 + n2; cout << "Case " << i << ": " << n3 << endl; } return 0; }
Subscribe to:
Posts (Atom)