├── A ├── AntonAndLetters │ ├── input.txt │ ├── output.txt │ ├── sol │ └── sol.cpp ├── ArrivalOfTheGeneral │ ├── input.txt │ ├── output.txt │ ├── sol │ └── sol.cpp ├── BeautifulMatrix │ ├── input.txt │ ├── output.txt │ ├── sol │ └── sol.cpp ├── ChatRoom │ ├── input.txt │ ├── output.txt │ ├── sol │ └── sol.cpp ├── CheapTravel │ ├── input.txt │ ├── output.txt │ ├── sol │ └── sol.cpp └── Dragons │ ├── input.txt │ ├── output.txt │ ├── sol │ └── sol.cpp ├── CodeJam ├── Vestigium.cpp ├── a.out └── input.txt └── week3 ├── a.out ├── car_fueling.cpp ├── change.cpp ├── dot_product.cpp └── fractional_knapsack.cpp /A/AntonAndLetters/input.txt: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /A/AntonAndLetters/output.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /A/AntonAndLetters/sol: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mustafa-Hassan2001/Computer-programing/2a4b3c4679e91cf42c2044475cbf8c9302a8157b/A/AntonAndLetters/sol -------------------------------------------------------------------------------- /A/AntonAndLetters/sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | ios_base::sync_with_stdio(false); cin.tie(NULL); 8 | 9 | #ifndef ONLINE_JUDGE 10 | //for getting input from input.txt 11 | freopen("input.txt", "r", stdin); 12 | //for writing output to output.txt 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | string s; 17 | getline(cin,s); 18 | //cout< 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | ios_base::sync_with_stdio(false); cin.tie(NULL); 8 | 9 | #ifndef ONLINE_JUDGE 10 | //for getting input from input.txt 11 | freopen("input.txt", "r", stdin); 12 | //for writing output to output.txt 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | pair < int, int > max = {-1, -1}; 17 | pair < int, int > min = {101, 101}; 18 | 19 | int n; 20 | cin>>n; 21 | int a[n]; 22 | for(int i = 0; i < n; i++) cin>>a[i]; 23 | 24 | for(int i = 0, j = n - 1; i < n, j >= 0; i++, j--){ 25 | if(max.first < a[i]){ 26 | max.first = a[i]; 27 | max.second = i; 28 | } 29 | if(min.first > a[j]){ 30 | min.first = a[j]; 31 | min.second = j; 32 | } 33 | } 34 | int change = 0, shiftMax = 0, shiftMin = 0; 35 | 36 | if(max.second != 0){ 37 | shiftMax = max.second; 38 | } 39 | if(min.second != n - 1){ 40 | shiftMin = n - 1 - min.second; 41 | if(max.second > min.second) 42 | shiftMin--; 43 | } 44 | 45 | change = shiftMin + shiftMax; 46 | 47 | //cout< 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | ios_base::sync_with_stdio(false); cin.tie(NULL); 8 | 9 | #ifndef ONLINE_JUDGE 10 | //for getting input from input.txt 11 | freopen("input.txt", "r", stdin); 12 | //for writing output to output.txt 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | int n = 5, row = -1, col = -1, input = -1; 17 | 18 | for(int i = 0; i < n; i++){ 19 | for(int j = 0; j < n; j++){ 20 | cin>>input; 21 | if(input){ 22 | row = i + 1; 23 | col = j + 1; 24 | } 25 | } 26 | } 27 | int ans = abs(3 - row) + abs(3- col); 28 | cout< 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | ios_base::sync_with_stdio(false); cin.tie(NULL); 8 | 9 | #ifndef ONLINE_JUDGE 10 | //for getting input from input.txt 11 | freopen("input.txt", "r", stdin); 12 | //for writing output to output.txt 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | string pat = "hello"; 17 | string s; 18 | cin>>s; 19 | int j = 0, flag = 0; 20 | for(int i = 0; i < s.size(); i++){ 21 | if(s[i] == pat[j]){ 22 | j++; 23 | } 24 | if(j == (pat.size())){ 25 | flag = 1; 26 | break; 27 | } 28 | 29 | } 30 | if(flag) 31 | cout<<"YES\n"; 32 | else 33 | cout<<"NO\n"; 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /A/CheapTravel/input.txt: -------------------------------------------------------------------------------- 1 | 10 3 5 1 -------------------------------------------------------------------------------- /A/CheapTravel/output.txt: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /A/CheapTravel/sol: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mustafa-Hassan2001/Computer-programing/2a4b3c4679e91cf42c2044475cbf8c9302a8157b/A/CheapTravel/sol -------------------------------------------------------------------------------- /A/CheapTravel/sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | ios_base::sync_with_stdio(false); cin.tie(NULL); 8 | 9 | #ifndef ONLINE_JUDGE 10 | //for getting input from input.txt 11 | freopen("input.txt", "r", stdin); 12 | //for writing output to output.txt 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | ll n, m, a, b; 17 | cin>>n>>m>>a>>b; 18 | ll ans = 0, numOfSpecialTicket, numOfNormalTicket; 19 | 20 | if((m * a) > b){ 21 | numOfNormalTicket = n % m; 22 | numOfSpecialTicket = (n - numOfNormalTicket) / m; 23 | 24 | ans = (numOfNormalTicket * a) + (numOfSpecialTicket * b); 25 | 26 | ans = min(ans, ((numOfSpecialTicket + 1) * b)); 27 | } 28 | else{ 29 | ans = n * a; 30 | } 31 | 32 | cout< 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | ios_base::sync_with_stdio(false); cin.tie(NULL); 8 | 9 | #ifndef ONLINE_JUDGE 10 | //for getting input from input.txt 11 | freopen("input.txt", "r", stdin); 12 | //for writing output to output.txt 13 | freopen("output.txt", "w", stdout); 14 | #endif 15 | 16 | ll s, n, x, y; 17 | le bool flag = true; 18 | multimap < ll, ll > m; 19 | cin>>s>>n; 20 | for(ll i = 0; i < n; i++){ 21 | cin>>x>>y; 22 | m.insert({x, y}); 23 | } 24 | for(auto a : m){ 25 | if(s > a.first){ 26 | s += a.second; 27 | } 28 | else{ 29 | cout<<"NO"; 30 | flag = false; 31 | break; 32 | } 33 | } 34 | if(flag) 35 | cout<<"YES"; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /CodeJam/Vestigium.cpp: -------------------------------------------------------------------------------- 1 | /* Output 2 | Case #1: 4 0 0 3 | Case #2: 9 4 4 4 | Case #3: 8 0 2 5 | */ 6 | 7 | #include 8 | using namespace std; 9 | typedef long long int ll; 10 | #define f(i,n) for(ll i=0; i=0; i--) 12 | 13 | int main(){ 14 | ll t, Case = 1; 15 | cin>>t; 16 | do{ 17 | ll n,i,j; 18 | cin>>n; 19 | vector < vector < ll > > arr; 20 | 21 | f(i,n){ 22 | vector < ll > temp; 23 | f(j,n){ 24 | ll x; 25 | cin>>x; 26 | temp.push_back(x); 27 | } 28 | arr.push_back(temp); 29 | } 30 | ll trace = 0, row = 0, column = 0; 31 | unordered_map < ll,int > mapRow; 32 | unordered_map < ll,int > mapColumn; 33 | 34 | f(i,n){ 35 | mapRow.clear(); 36 | mapColumn.clear(); 37 | f(j,n){ 38 | if(i == j) trace += arr[i][j]; 39 | mapRow[arr[i][j]]++; 40 | mapColumn[arr[j][i]]++; 41 | } 42 | for(auto a : mapRow){ 43 | if(a.second > 1){ 44 | row++; 45 | break; 46 | } 47 | } 48 | for(auto a : mapColumn){ 49 | if(a.second > 1){ 50 | column++; 51 | break; 52 | } 53 | } 54 | } 55 | cout<<"Case#"< 2 | #include 3 | 4 | using std::cin; 5 | using std::cout; 6 | using std::vector; 7 | using std::max; 8 | 9 | int compute_min_refills(int dist, int tank, vector & stops) { 10 | // write your code here 11 | int n = stops.size()-1; 12 | int numRefill = 0, currentRefill = 0; 13 | while(currentRefill <= n) 14 | { 15 | int lastRefill = currentRefill; 16 | while(currentRefill <= n && (stops[currentRefill + 1] - stops[lastRefill] <= tank)) 17 | { 18 | currentRefill = currentRefill + 1; 19 | } 20 | if(currentRefill == lastRefill) 21 | { 22 | return -1; 23 | } 24 | if(currentRefill <= n) 25 | { 26 | numRefill = numRefill + 1; 27 | } 28 | } 29 | return numRefill; 30 | } 31 | 32 | 33 | int main() { 34 | int d = 0; 35 | cin >> d; 36 | int m = 0; 37 | cin >> m; 38 | int n = 0; 39 | cin >> n; 40 | 41 | vector stops(n); 42 | for (size_t i = 0; i < n; ++i) 43 | cin >> stops.at(i); 44 | stops.push_back(d); 45 | stops.insert(stops.begin(), 0); 46 | 47 | cout << compute_min_refills(d, m, stops) << "\n"; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /week3/change.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int get_change(int m) { 4 | //write your code here 5 | int n=0; 6 | while(m >= 10){ 7 | m-=10; 8 | n++; 9 | } 10 | while(m >= 5){ 11 | m-=5; 12 | n++; 13 | } 14 | while(m >= 1){ 15 | m-=1; 16 | n++; 17 | } 18 | return n; 19 | } 20 | 21 | int main() { 22 | int m; 23 | std::cin >> m; 24 | std::cout << get_change(m) << '\n'; 25 | } 26 | -------------------------------------------------------------------------------- /week3/dot_product.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //using std::vector; 6 | using namespace std; 7 | long long max_dot_product(vector& a, vector& b) { 8 | // write your code here 9 | sort(a.begin(),a.end()); 10 | sort(b.begin(),b.end()); 11 | long long result = 0; 12 | for (size_t i = 0; i < a.size(); i++) { 13 | result += ((long long) a[i]) * b[i]; 14 | } 15 | return result; 16 | } 17 | 18 | int main() { 19 | size_t n; 20 | std::cin >> n; 21 | vector a(n), b(n); 22 | for (size_t i = 0; i < n; i++) { 23 | std::cin >> a[i]; 24 | } 25 | for (size_t i = 0; i < n; i++) { 26 | std::cin >> b[i]; 27 | } 28 | std::cout << max_dot_product(a, b) << std::endl; 29 | } 30 | -------------------------------------------------------------------------------- /week3/fractional_knapsack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using std::vector; 5 | 6 | int sort(vector &weights, vector &values, int n) 7 | { 8 | for(int i = 0; i < n; i++) 9 | { 10 | for(int j = i+1; j < n; j++) 11 | { 12 | if(((double)values[i]/weights[i])<((double)values[j]/weights[j])) 13 | { 14 | double temp = values[i]; 15 | values[i] = values[j]; 16 | values[j] = temp; 17 | temp = weights[i]; 18 | weights[i] = weights[j]; 19 | weights[j] = temp; 20 | 21 | } 22 | } 23 | } 24 | return 0; 25 | } 26 | 27 | double get_optimal_value(int capacity, vector weights, vector values) { 28 | double value = 0.0; 29 | 30 | // write your code here 31 | for(int i = 0; i <= sizeof(weights); i++) 32 | { 33 | if(capacity == 0) 34 | return value; 35 | 36 | int a = weights[i]> n >> capacity; 49 | vector values(n); 50 | vector weights(n); 51 | for (int i = 0; i < n; i++) { 52 | std::cin >> values[i] >> weights[i]; 53 | } 54 | sort(weights,values,n); 55 | double optimal_value = get_optimal_value(capacity, weights, values); 56 | 57 | std::cout.precision(10); 58 | std::cout << optimal_value << std::endl; 59 | return 0; 60 | } 61 | --------------------------------------------------------------------------------