Posts

Image
 MySQL Setup Download MySQL zip (https://dev.mysql.com/downloads/mysql/) Save zip file any location Unzip file Enter bin folder of unzip directory     -  Open a command prompt on this directory path     - Run following command                     mysqld --initialize --console    - Copy temporary generated password         - Run following command                       mysqld --console     For changing password :     - Open a new  command prompt on this bin directory path      - Run following command and press Enter key                mysql -u root -p     - Then command prompt wants password. Please enter the copied password. And press Enter key.     - Then run following command for changing root password. ...

10887 - Concatenation of Languages Solution Python

totalCase = int ( input ()) i = 1 while i <= totalCase: m, n = [ int (x) for x in input ().split()] mySet1 = set () for j in range (m): mySet1.add( input ().strip()) mySet2 = set () for j in range (n): mySet2.add( input ().strip()) mySet = set () for x in mySet1: for y in mySet2: mySet.add(x + y) print ( f"Case { i } : { len (mySet) } " ) i += 1

uva-10855 Rotated squares Solution in Python

while True : N , n = [ int (x) for x in input ().split()] if N == 0 and n == 0 : break arr = [[ '' ] * N for i in range (N)] arr0 = [[ '' ] * n for i in range (n)] arr90 = [[ '' ] * n for i in range (n)] arr180 = [[ '' ] * n for i in range (n)] arr270 = [[ '' ] * n for i in range (n)] for i in range (N): s = input () k = 0 for j in s: arr[i][k] = j k += 1 for i in range (n): s = input () k = 0 for j in s: arr0[i][k] = j arr90[k][n - 1 - i] = j arr180[n - 1 - i][n - 1 - k] = j arr270[n - 1 - k][i] = j k += 1 r1 , r2 , r3 , r4 = 0 , 0 , 0 , 0 for i in range (N - n + 1 ): for j in range (N - n + 1 ): t1 = [] for k in range (n): t1.insert(k , arr[i + k][j:j + n]) if t1 == arr0: r1 += 1 ...

uva 10703 - Free spots Solution in Python

while True : w , h , n = [ int (x) for x in input ().strip().split()] if w == 0 and h == 0 and n == 0 : break ls = [] for i in range (h): ls.insert(i , [ 0 ] * w) result = w * h for i in range (n): x1 , y1 , x2 , y2 = [ int (x) for x in input ().strip().split()] if x1 > x2: x1 , x2 = x2 , x1 if y1 > y2: y1 , y2 = y2 , y1 x1 -= 1 y1 -= 1 for j in range (y1 , y2): for k in range (x1 , x2): if ls[j][k] == 0 : result -= 1 ls[j][k] = 1 if result == 0 : print ( "There is no empty spots." ) elif result == 1 : print ( "There is one empty spot." ) else : print ( f"There are { result } empty spots." ) input ()  

UVA-414 Machined Surfaces Solution in Python

while True : x = int ( input ()) if x == 0 : break minimum = 25 ls = [] for i in range (x): s = input ().strip() index1 = s.find( " " ) if index1 >= 0 : index2 = s.find( "X" , index1) delta = index2 - index1 ls.append(delta) if delta < minimum: minimum = delta else : ls.append( 0 ) minimum = 0 result = 0 for i in range (x): result = result + ls[i] - minimum print (result)

Dynamic 2D Array in C++ with explanation

Dynamic 2D Array In C++ Try to create integer 2D array of 4 row and 3 columns. Code snippet: int ** a = new int * [4];//line1 for ( int i = 0; i < 4; i++) {//line2 a[i] = new int [3];//line3 } //line4 Explanation: Let, Address of a is 0x100 and size of int is 4. So, Address of a[0] is 0x100, address of a[1] is 0x104, address of a[2] is 0x108 and so on. a[0]                             a[1]                        a[2]                          a[3] 0x100                   ...

uva 10507 Waking up brain Solution

Waking up brain Solution uva id : erfan05 Accepted Time : 0.000 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string> #include<set> #include<map> using namespace std; typedef set<char> set_char; typedef map<char, set_char> map_char_set_char; typedef map_char_set_char::iterator map_char_set_char_iterator; typedef set_char::iterator set_char_iterator; int main(){ map_char_set_char mymap; set_char_iterator sit,it; map_char_set_char_iterator mit; set_char life,life_progress; string str; char ch1, ch2; int i, n, year, row; while (cin >> n >> row){ cin >> str; life.clear(); life_progress.clear(); mymap.clear(); life.insert(str[0]); life.insert(str[1]); life.insert(str[2]); for (i = 0; i < row; i++){ cin >> str; ch1 = str[0]; ch2 = str[1]; sit = life.find(ch1); if (sit == life.end()){ mit = mymap.find(ch1); if (mit == mymap....

uva 10895 Matrix Transpose Solution

  Matrix Transpose Solution uva id : erfan05 Accepted Time : 0.000 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<queue> #include<vector> #include<map> #include<set> #include<string> using namespace std; typedef vector<int> vector_int; typedef map<int, vector_int> map_int_vector_int; int main(){ freopen("input.txt", "r", stdin); map_int_vector_int index_map,value_map; vector_int index, value; int i, j, m, n, val, pos, x; while (cin >> m >> n){ index_map.clear(); value_map.clear(); for (i = 1; i <= n; i++){ vector_int v1,v2; index_map[i] = v1; value_map[i] = v2; } for (i = 1; i <= m; i++){ cin >> x; if (x == 0) continue; index.clear(); for (j = 1; j <= x; j++){ cin >> pos; index_map[pos].push_back(i); index.push_back(pos); } for (j = 0; j < x; ...

uva - 599 The Forrest for the Trees Solution

The Forrest for the Trees  #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<queue> #include<vector> #include<map> #include<set> #include<string> using namespace std; typedef vector<char> vector_char; typedef map<char, vector_char> map_vector_char; typedef set<char> set_char; typedef map_vector_char::iterator map_vector_char_iterator; typedef set_char::iterator set_char_iterator; int main(){ freopen("input.txt", "r", stdin); int i,test,forest,acorn; string str; char ch1,ch2; map_vector_char mymap; map_vector_char_iterator mit; set_char myset; set_char_iterator sit; queue<char> q; cin >> test; getchar(); while (test--){ mymap.clear(); while (true){ getline(cin, str); if (str[0] == '*') break; ch1 = str[1]; ch2 = str[3]; mit = mymap.find(ch1); if (mit == mymap.end()){ vector_c...

uva 11503 Virtual Friends Solution

uva 11503 Virtual Friends #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<map> #include<string> using namespace std; map<string, int> mymap; map<string, int> ::iterator mit; int val[100005], parent[100005]; int findParent(int x){ if (parent[x] == x) return x; else return findParent(parent[x]); } int main(){ int i, x, y, n, test; string str1, str2; cin >> test; while (test--){ cin >> n; for (i = 0; i < 100005; i++){ parent[i] = i; val[i] = 1; } mymap.clear(); for (i = 0; i < n; i++){ cin >> str1 >> str2; mit = mymap.find(str1); if (mit == mymap.end()){ x = mymap.size(); mymap[str1] = x; } else{ x = mit->second; } mit = mymap.find(str2); if (mit == mymap.end()){ y = mymap.size(); mymap[str2] = y; } else{ y = mit->second; } x = findParent(x); y = findParent(y); if (...

uva - 11995 I Can Guess the Data Structure! Solution

uva - 11995 I Can Guess the Data Structure! #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<queue> #include<vector> #include<functional> #include<stack> using namespace std; int main(){ int arr[3]; stack<int> st; queue<int> q; priority_queue<int> pq; int i, z, n, x, y; while (cin >> n){ arr[0] = arr[1] = arr[2] = 0; while (!st.empty()) st.pop(); while (!q.empty()) q.pop(); while (!pq.empty()) pq.pop(); for (i = 0; i < n; i++){ cin >> x >> y; if (x == 1){ if (arr[0] != 2) st.push(y); if (arr[1] != 2) q.push(y); if (arr[2] != 2) pq.push(y); } else{ if (!q.empty() && arr[1] != 2){ z = q.front(); if (z == y) arr[1] = 1; else arr[1] = 2; q.pop(); } else{ arr[1] = 2; } if (!st.empty() && arr[0] != 2){ z = st.top(); ...

uva - 540 Team Queue Solution

uva - 540 Team Queue Solution uva id: erfan05 Accepted Time: 0.070 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<map> #include<algorithm> #include<queue> #include<string> using namespace std; int arr[1000000], task_value[1000]; int main(){ map<int, queue<int>> mymap; map<int, queue<int>>::iterator mit; map<int, int> task_value_map; int  n, x, i, team, max_value, y, kase=1; string str; while (cin >> team){ if (team == 0) break; cout << "Scenario #" << kase++ << endl; for (i = 1; i <= team; i++){ cin >> n; while (n--){ cin >> x; arr[x] = i; } } max_value = 1; fill(task_value, task_value + team + 1, 0); mymap.clear(); while (cin >> str){ if (str[0] == 'E'){ cin >> x; y = arr[x]; if (task_value[y] == 0){ task_value[y] = max_value; queue...

uva - 10194 - Football (aka Soccer) Solution

uva - 10194 - Football (aka Soccer) Solution #include<iostream> #include<string> #include<vector> #include<algorithm> #include<map> #include<string.h> #include<stdio.h> using namespace std; class Team{ public: string name; int b, c, d, e, f, g, h, i; Team(){ b = c = d = e = f = g = h = i = 0; } }; void split_string(string &str, string delimiter, vector<string> &result){ string temp,temp2; temp.resize(str.length()); copy(str.begin(), str.end(),temp.begin()); int pos; while (true){ if (temp.length() == 0) break; pos = temp.find(delimiter); if (pos == -1){ result.push_back(temp); break; } temp2 = temp.substr(0, pos); if (temp2.length()!=0) result.push_back(temp2); temp = temp.substr(pos + delimiter.length()); } } int string_to_int(string str){ int i, sum = 0, len = str.length(),mul=1; for (i = len - 1; i >= 0; i--){ sum += (str[i] - 48)*mul; ...