├── README.md ├── .gitignore ├── A_Watermelon.bin ├── A_Integer_Moves.bin ├── B_XY_Sequence.bin ├── A_Madoka_and_Math_Dad.bin ├── C_Bracket_Sequence_Deletion.bin ├── A. Colorful Stones.cpp ├── dynamic-programming └── leetcode │ └── Climbing Stairs.cpp ├── A. Night at the Museum.cpp ├── A. Black Square.cpp ├── A. Magnets.cpp ├── div 02_(0) └── A. Is your horseshoe on the other hoof?.cpp ├── A. Buy a Shovel.cpp ├── A. Police Recruits.cpp ├── .A_Watermelon.cpp_3caa30919ee32e8b4ab5038fde814ce1.prob ├── B_Madoka_and_the_Elegant_Gift.cpp ├── A. Word.cpp ├── A_Madoka_and_Math_Dad.cpp ├── .A_Integer_Moves.cpp_82e06c9dbd3c2d74d248bcf916b4dc95.prob ├── A. Stable Arrangement of Rooks.cpp ├── A. Stones on the Table.cpp ├── A. Games.cpp ├── .B_XY_Sequence.cpp_9bec5fb44f8068d0a524da251eb57614.prob ├── A. Boy or Girl.cpp ├── .C_Bracket_Sequence_Deletion.cpp_a00504ef565cab22780e8e14f8d46eed.prob ├── Good Bye 2021: 2022 is NEAR ├── A. Integer Diversity.cpp └── B. Mirror in the String.cpp ├── .B_Madoka_and_the_Elegant_Gift.cpp_8e51bba70e852cca256d3a5d7762574d.prob ├── A. Petya and Strings.cpp ├── A. Gravity Flip.cpp ├── div 3_(0) ├── B. Squares and Cubes.cpp ├── A. Square String?.cpp └── C. Wrong Addition.cpp └── Hello 2022 └── A. Stable Arrangement of Rooks.cpp /README.md: -------------------------------------------------------------------------------- 1 | # Codeforces-training- -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | a.out 2 | main.cpp 3 | .vscode 4 | 5 | -------------------------------------------------------------------------------- /A_Watermelon.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anasjaidi/Codeforces-training/HEAD/A_Watermelon.bin -------------------------------------------------------------------------------- /A_Integer_Moves.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anasjaidi/Codeforces-training/HEAD/A_Integer_Moves.bin -------------------------------------------------------------------------------- /B_XY_Sequence.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anasjaidi/Codeforces-training/HEAD/B_XY_Sequence.bin -------------------------------------------------------------------------------- /A_Madoka_and_Math_Dad.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anasjaidi/Codeforces-training/HEAD/A_Madoka_and_Math_Dad.bin -------------------------------------------------------------------------------- /C_Bracket_Sequence_Deletion.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anasjaidi/Codeforces-training/HEAD/C_Bracket_Sequence_Deletion.bin -------------------------------------------------------------------------------- /A. Colorful Stones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | string s, t; 7 | cin >> s >> t; 8 | int i, j; 9 | for (i = 0, j = 0; s[i], t[j];) 10 | { 11 | if (s[i] == t[j]) 12 | i++; 13 | j++; 14 | } 15 | cout << i + 1 << '\n'; 16 | } 17 | 18 | int main() 19 | { 20 | solve(); 21 | } -------------------------------------------------------------------------------- /dynamic-programming/leetcode/Climbing Stairs.cpp: -------------------------------------------------------------------------------- 1 | int tab[50] = {0}; 2 | 3 | 4 | class Solution { 5 | public: 6 | int climbStairs(int n) { 7 | if (n <= 3) 8 | return n; 9 | if (tab[n]) 10 | return tab[n]; 11 | else 12 | { 13 | tab[n] = climbStairs(n - 1) + climbStairs(n - 2); 14 | } 15 | return tab[n]; 16 | } 17 | }; -------------------------------------------------------------------------------- /A. Night at the Museum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() 6 | { 7 | string s; 8 | cin >> s; 9 | int x = 0; 10 | x = min(abs(s[0] - 'a'), (26 - abs(s[0] - 'a'))); 11 | for (size_t i = 0; s[i + 1]; i++) 12 | x += min(abs(s[i] - s[i + 1]), (26 - abs(s[i] - s[i + 1]))); 13 | cout << x << '\n'; 14 | } 15 | 16 | int main (int argc, char *argv[]) 17 | { 18 | solve(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /A. Black Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std ; 6 | 7 | void solve(void) 8 | { 9 | int c = 0, n, r = 0; 10 | int arr[5] = {0}; 11 | string str; 12 | for (size_t i = 1; i < 5; i++) 13 | cin >> arr[i]; 14 | cin >> str; 15 | for (size_t i = 0; str[i]; i++) 16 | r += arr[str[i] - 48]; 17 | cout << r << endl; 18 | } 19 | 20 | int main() 21 | { 22 | solve(); 23 | } -------------------------------------------------------------------------------- /A. Magnets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std ; 7 | 8 | void solve(void) 9 | { 10 | int c = 1; 11 | int n; 12 | cin >> n; 13 | vector arr(n,0); 14 | for (size_t i = 0; i < n; i++) 15 | cin >> arr[i]; 16 | for (size_t i = 0; i < n - 1; i++) 17 | if (arr[i] != arr[i + 1]) 18 | c++; 19 | cout << c << endl; 20 | } 21 | 22 | int main() 23 | { 24 | solve(); 25 | } -------------------------------------------------------------------------------- /div 02_(0)/A. Is your horseshoe on the other hoof?.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void solve() 6 | { 7 | int arr[4], c = 0; 8 | map map; 9 | for (size_t i = 0; i < 4; i++) 10 | { 11 | cin >> arr[i]; 12 | if (!map[arr[i]]) 13 | { 14 | c++; 15 | map[arr[i]] = 1; 16 | } 17 | } 18 | cout <<4 - c << endl; 19 | } 20 | 21 | int main() 22 | { 23 | solve(); 24 | } -------------------------------------------------------------------------------- /A. Buy a Shovel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std ; 6 | 7 | 8 | void solve(void) 9 | { 10 | int a , b , c = 0; 11 | cin >> a >> b; 12 | int m; 13 | for (size_t i = 1; i <= 10; i++) 14 | { 15 | m = i * a - b; 16 | if (m % 10 == 0 || (i * a % 10 == 0)) 17 | { 18 | c = i; 19 | break; 20 | } 21 | } 22 | 23 | cout << c << endl; 24 | } 25 | 26 | int main() 27 | { 28 | solve(); 29 | } -------------------------------------------------------------------------------- /A. Police Recruits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std ; 6 | 7 | void solve(void) 8 | { 9 | int c = 0, re = 0, n , i , m , r = 0; 10 | cin >> n; 11 | for (i = 0; i < n; i++) 12 | { 13 | cin >> m; 14 | if (m < 0 && !re) 15 | r++; 16 | else if (m < 0 && re) 17 | re--; 18 | else if (m > 0) 19 | re = re + m; 20 | } 21 | 22 | cout << r << endl; 23 | } 24 | 25 | int main() 26 | { 27 | solve(); 28 | } -------------------------------------------------------------------------------- /.A_Watermelon.cpp_3caa30919ee32e8b4ab5038fde814ce1.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Watermelon","group":"Codeforces - Codeforces Beta Round #4 (Div. 2 Only)","url":"https://codeforces.com/problemset/problem/4/A","interactive":false,"memoryLimit":64,"timeLimit":1000,"tests":[{"id":1647959765564,"input":"8","output":"YES"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AWatermelon"}},"batch":{"id":"3b8fe179-e17f-45b3-af87-b862fad1e927","size":1},"srcPath":"/Users/ajaidi/Documents/Data-Structure/div2 with dmi/A_Watermelon.cpp"} -------------------------------------------------------------------------------- /B_Madoka_and_the_Elegant_Gift.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void solve() 7 | { 8 | int n , m; 9 | cin >> n >> m; 10 | vector s(n); 11 | for (size_t i = 0; i < n; i++) cin >> s[i]; 12 | for (size_t i = 0; i < n; i++) 13 | { 14 | for (size_t j = 0; j < m; j++) 15 | { 16 | 17 | } 18 | 19 | } 20 | 21 | } 22 | 23 | int main() 24 | { 25 | int n; 26 | cin >> n; 27 | for (size_t i = 0; i < n; i++) 28 | solve(); 29 | 30 | } -------------------------------------------------------------------------------- /A. Word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std ; 6 | 7 | void solve(void) 8 | { 9 | string str; 10 | int c = 0; 11 | cin >> str; 12 | for (size_t i = 0; str[i]; i++) 13 | if (isupper(str[i])) 14 | c++; 15 | if (c > str.length() / 2) 16 | for (size_t i = 0; str[i]; i++) 17 | str[i] = toupper(str[i]); 18 | else 19 | for (size_t i = 0; str[i]; i++) 20 | str[i] = tolower(str[i]); 21 | cout << str << endl; 22 | } 23 | 24 | int main() 25 | { 26 | solve(); 27 | } -------------------------------------------------------------------------------- /A_Madoka_and_Math_Dad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void solve() 8 | { 9 | int n; 10 | cin >> n ; 11 | int c = 0; 12 | int i; 13 | i = n % 3; 14 | if (!i) 15 | i = 2; 16 | while (c < n) 17 | { 18 | c += i; 19 | cout << i; 20 | if (i == 2) 21 | i = 1; 22 | else 23 | i++; 24 | } 25 | cout << endl; 26 | } 27 | 28 | int main() 29 | { 30 | int n; 31 | cin >> n; 32 | for (int i = 0; i < n; i++) 33 | solve(); 34 | } -------------------------------------------------------------------------------- /.A_Integer_Moves.cpp_82e06c9dbd3c2d74d248bcf916b4dc95.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Integer Moves","group":"Codeforces - Educational Codeforces Round 125 (Rated for Div. 2)","url":"https://codeforces.com/contest/1657/problem/0","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1647960390990,"input":"3\n8 6\n0 0\n9 15","output":"1\n0\n2"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AIntegerMoves"}},"batch":{"id":"ffdcd633-4fe2-483a-b090-6d35a73da8db","size":1},"srcPath":"/Users/ajaidi/Documents/Data-Structure/div2 with dmi/A_Integer_Moves.cpp"} -------------------------------------------------------------------------------- /A. Stable Arrangement of Rooks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void solve() 6 | { 7 | int x , y , c = 0; 8 | cin >> x >> y; 9 | for (size_t i = 0; i < x; i++) 10 | { 11 | for (size_t j = 0; j < x; j++) 12 | { 13 | // if (abs(i - j)> 1) 14 | // c++; 15 | } 16 | 17 | } 18 | cout << c << endl; 19 | } 20 | 21 | 22 | int main() 23 | { 24 | int t ; 25 | //cin >> t; 26 | cout << t ; 27 | // while (t != 0) 28 | // { 29 | // solve(); 30 | // t--; 31 | // } 32 | } -------------------------------------------------------------------------------- /A. Stones on the Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void selectionSort(int arr[], int n); 5 | void swap(char *xp, char *yp) 6 | { 7 | char temp = *xp; 8 | *xp = *yp; 9 | *yp = temp; 10 | } 11 | void solve() 12 | { 13 | char str[1000]; 14 | int n; 15 | int c = 0; 16 | std::cin >> n; 17 | std::cin >> str; 18 | for (size_t i = 0; i < n; i += 1) 19 | { 20 | if (str[i] == str[i + 1]) 21 | c++; 22 | } 23 | std::cout << c << std::endl; 24 | } 25 | 26 | signed main() 27 | { 28 | int t; 29 | //std::cin >> t; 30 | t = 1; 31 | while (t--) 32 | { 33 | solve(); 34 | } 35 | } -------------------------------------------------------------------------------- /A. Games.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() 6 | { 7 | int t; 8 | int c = 0; 9 | cin >> t; 10 | int team[t][2]; 11 | for (size_t i = 0; i < t; i++) 12 | cin >> team[i][0] >> team[i][1]; 13 | for (size_t i = 0; i < t - 1; i++) 14 | { 15 | for (size_t j = i + 1; j < t; j++) 16 | { 17 | if (team[i][0] == team[j][1]) 18 | c++; 19 | if (team[i][1] == team[j][0]) 20 | c++; 21 | } 22 | 23 | } 24 | cout << c << '\n'; 25 | } 26 | 27 | int main() 28 | { 29 | solve(); 30 | } -------------------------------------------------------------------------------- /.B_XY_Sequence.cpp_9bec5fb44f8068d0a524da251eb57614.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. XY Sequence","group":"Codeforces - Educational Codeforces Round 125 (Rated for Div. 2)","url":"https://codeforces.com/contest/1657/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3","output":"15\n4000000000\n-10","id":1647963581200}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BXYSequence"}},"batch":{"id":"6810e80b-e984-4112-834c-5863a96e4998","size":1},"srcPath":"/Users/ajaidi/Documents/Data-Structure/div2 with dmi/B_XY_Sequence.cpp"} -------------------------------------------------------------------------------- /A. Boy or Girl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int check(string str, char c, int p) 7 | { 8 | for (size_t i = 0; i < p; i++) 9 | if (c == str[i]) 10 | return 0; 11 | return 1; 12 | } 13 | 14 | void solve() 15 | { 16 | string str; 17 | cin >> str; 18 | int c = 0; 19 | char hash[256]; 20 | for (size_t i = 0; str[i]; i++) 21 | if (check(str,str[i],i)) 22 | c++; 23 | if (c & 1) 24 | cout << "IGNORE HIM!" << endl; 25 | else 26 | cout << "CHAT WITH HER!" << endl; 27 | 28 | } 29 | 30 | 31 | signed main() 32 | { 33 | int t; 34 | //std::cin >> t; 35 | t = 1; 36 | while (t--) 37 | { 38 | solve(); 39 | } 40 | } -------------------------------------------------------------------------------- /.C_Bracket_Sequence_Deletion.cpp_a00504ef565cab22780e8e14f8d46eed.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Bracket Sequence Deletion","group":"Codeforces - Educational Codeforces Round 125 (Rated for Div. 2)","url":"https://codeforces.com/contest/1657/problem/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1647965977214,"input":"5\n2\n()\n3\n())\n4\n((((\n5\n)((()\n6\n)((()(","output":"1 0\n1 1\n2 0\n1 0\n1 1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CBracketSequenceDeletion"}},"batch":{"id":"100659e4-a4ab-4daf-bfad-cd30d6e1618a","size":1},"srcPath":"/Users/ajaidi/Documents/Data-Structure/div2 with dmi/C_Bracket_Sequence_Deletion.cpp"} -------------------------------------------------------------------------------- /Good Bye 2021: 2022 is NEAR/A. Integer Diversity.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | using namespace std; 6 | 7 | void solve() 8 | { 9 | int t , n; 10 | cin >> t; 11 | int arr; 12 | map map1; 13 | for (int i = 0; i < t ; i++) 14 | { 15 | cin >> n; 16 | for (size_t j = 0; j < n; j++) 17 | { 18 | cin >> arr; 19 | if (!map1[arr]) 20 | map1[arr] = 1; 21 | else if (map1[arr] && !(map1[-arr]) && (arr)) 22 | map1[-arr] = 1; 23 | } 24 | cout << map1.size() << endl; 25 | map1.clear(); 26 | } 27 | } 28 | 29 | int main() 30 | { 31 | solve(); 32 | } -------------------------------------------------------------------------------- /.B_Madoka_and_the_Elegant_Gift.cpp_8e51bba70e852cca256d3a5d7762574d.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Madoka and the Elegant Gift","group":"Codeforces - Codeforces Round #777 (Div. 2)","url":"https://codeforces.com/contest/1647/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1647815075432,"input":"5\n3 3\n100\n011\n011\n3 3\n110\n111\n110\n1 5\n01111\n4 5\n11111\n01010\n01000\n01000\n3 2\n11\n00\n11","output":"YES\nNO\nYES\nNO\nYES"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BMadokaAndTheElegantGift"}},"batch":{"id":"1b80e82c-40bc-40f8-a8f0-e1146c1c7df3","size":1},"srcPath":"/Users/ajaidi/Documents/Codeforces-training/B_Madoka_and_the_Elegant_Gift.cpp"} -------------------------------------------------------------------------------- /A. Petya and Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int ft_strncmp(char *s1, char *s2) 5 | { 6 | int i; 7 | 8 | i = 0; 9 | while (s1[i] && s2[i] && (s1[i] == s2[i])) 10 | i++; 11 | return ((char)s1[i] - (char)s2[i]); 12 | } 13 | 14 | void solve() 15 | { 16 | int i = 0, r; 17 | char str1[1000]; 18 | char str2[1000]; 19 | std::cin >> str1; 20 | std::cin >> str2; 21 | while (str1[i]) 22 | { 23 | if (str1[i] >= 65 && str1[i] <= 90) 24 | str1[i] += 32; 25 | if (str2[i] >= 65 && str2[i] <= 90) 26 | str2[i] += 32; 27 | i++; 28 | } 29 | r = ft_strncmp(str1, str2); 30 | if (r > 0) 31 | std::cout << 1 << std::endl; 32 | else if (0 > r) 33 | std::cout << -1 << std::endl; 34 | else 35 | std::cout << 0 << std::endl; 36 | } 37 | 38 | 39 | signed main() 40 | { 41 | int t; 42 | //std::cin >> t; 43 | t = 1; 44 | while (t--) 45 | { 46 | solve(); 47 | } 48 | } -------------------------------------------------------------------------------- /A. Gravity Flip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | 8 | void solve() 9 | { 10 | int n, i; 11 | cin >> n; 12 | int *arr = new int[n]; 13 | for (i = 0; i < n; i++) 14 | cin >> arr[i]; 15 | ////////////////////// 16 | /* method number 1 */ 17 | //////////////////// 18 | /* for (i = 0; i < n -1; i++) 19 | { 20 | for (size_t j = i + 1; j < n; j++) 21 | if (arr[i] > arr[j]) 22 | swap(arr[i], arr[j]); 23 | 24 | } */ 25 | ////////////////////// 26 | /* method number 2 */ 27 | //////////////////// 28 | /////////////////// 29 | sort(arr, arr + n); 30 | //////////////////// 31 | for (i = 0; i < n - 1; i++) 32 | cout << arr[i] << ' '; 33 | cout << arr[i] < 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | void solve() 11 | { 12 | long long n , x , sq; 13 | cin >> n; 14 | int c = 0; 15 | for (size_t i = 0; i < n; i++) 16 | { 17 | c = 0; 18 | cin >> x; 19 | map hash; 20 | for (size_t j = 1; j * j <= x; j++) 21 | { 22 | if ((j * j <= x) && !hash[j * j]) 23 | { 24 | c++; 25 | hash[j * j] = 1; 26 | } 27 | if ((j * j * j <= x) && (j != 1) && !hash[j * j * j]) 28 | { 29 | c++; 30 | hash[j * j * j] = 1; 31 | } 32 | } 33 | cout << c << endl; 34 | } 35 | 36 | } 37 | 38 | 39 | signed main() 40 | { 41 | int t; 42 | //std::cin >> t; 43 | t = 1; 44 | while (t--) 45 | { 46 | solve(); 47 | } 48 | } -------------------------------------------------------------------------------- /div 3_(0)/A. Square String?.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int ft_strcmp(string s1, string s2) 6 | { 7 | int i; 8 | 9 | i = 0; 10 | while (s1[i] && s2[i] && (s1[i] == s2[i])) 11 | i++; 12 | return ((char)s1[i] - (char)s2[i]); 13 | } 14 | 15 | void solve() 16 | { 17 | int n, h , i = 0, j = 0 , len; 18 | char str[101] = {0}; 19 | char s[101] = {0}; 20 | cin >> n; 21 | 22 | for (size_t x = 0; x < n; x++) 23 | { 24 | cin >> str; 25 | len = strlen(str); 26 | if (len & 1) 27 | cout << "NO" << endl; 28 | else 29 | { 30 | h = len / 2; 31 | j = 0; 32 | for (i = h; str[i]; i++) 33 | { 34 | s[j] = str[i]; 35 | j++; 36 | } 37 | s[j] = 0; 38 | str[h] = 0; 39 | if (!(ft_strcmp(s, str))) 40 | cout << "YES" << endl; 41 | else 42 | cout << "NO" << endl; 43 | } 44 | } 45 | 46 | } 47 | 48 | 49 | signed main() 50 | { 51 | int t; 52 | //std::cin >> t; 53 | t = 1; 54 | while (t--) 55 | { 56 | solve(); 57 | } 58 | } -------------------------------------------------------------------------------- /div 3_(0)/C. Wrong Addition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | void solve() 11 | { 12 | int n , lenx , leny, ix , iy, d; 13 | cin >> n; 14 | char x[100]; 15 | char y[100]; 16 | char r[100]; 17 | for (size_t i = 0; i < n; i++) 18 | { 19 | cin >> x >> y; 20 | lenx = strlen(x) - 1; 21 | leny = strlen(y) - 1; 22 | for (size_t z = leny; z >= 0;) 23 | { 24 | iy = atoi(y + z); 25 | ix = x[leny] - 48; 26 | if (iy - ix < 0) 27 | { 28 | z--; 29 | iy = atoi(y + z); 30 | continue ; 31 | } 32 | else 33 | { 34 | r[d] = (iy - ix) + 48; 35 | d++; 36 | lenx--; 37 | y[z]= 0; 38 | z--; 39 | } 40 | if (z < 0) 41 | break; 42 | } 43 | r[d] = 0; 44 | cout << r; 45 | } 46 | 47 | } 48 | 49 | 50 | signed main() 51 | { 52 | int t; 53 | //std::cin >> t; 54 | t = 1; 55 | while (t--) 56 | { 57 | solve(); 58 | } 59 | } -------------------------------------------------------------------------------- /Hello 2022/A. Stable Arrangement of Rooks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | typedef class s_players { 6 | public: 7 | int x ; 8 | int y; 9 | } t_player; 10 | 11 | void solve() 12 | { 13 | int x, y, c = 0 , px, py, z = 0; 14 | cin >> x >> y; 15 | t_player player[y]; 16 | for (size_t i = 0; i < x; i++) 17 | { 18 | for (size_t j = 0; j < x; j++) 19 | { 20 | if (z == y) 21 | { 22 | i = x + 1; 23 | break; 24 | } 25 | if (i == 0 && j == 0) 26 | { 27 | player[z].x = i; 28 | player[z].y = j; 29 | z++; 30 | continue; 31 | } 32 | px= (i - player[z - 1].x); 33 | py = (j - player[z - 1].y); 34 | if (px > 1 && py > 1) 35 | { 36 | player[z].x = i; 37 | player[z].y = j; 38 | z++; 39 | } 40 | } 41 | 42 | } 43 | if (z < y) 44 | cout << -1 << endl; 45 | else 46 | { 47 | z = 0; 48 | for (size_t i = 0; i < x; i++) 49 | { 50 | for (size_t j = 0; j < x; j++) 51 | { 52 | if (z < y && i == player[z].x && j == player[z].y) 53 | { 54 | cout << 'R'; 55 | z++; 56 | } 57 | else 58 | cout << '.'; 59 | } 60 | cout << endl; 61 | } 62 | 63 | } 64 | } 65 | 66 | int main() 67 | { 68 | int t ; 69 | cin >> t; 70 | while (t--) 71 | solve(); 72 | } -------------------------------------------------------------------------------- /Good Bye 2021: 2022 is NEAR/B. Mirror in the String.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | string ft_strcat(string dest, string src) 8 | { 9 | int i; 10 | int j; 11 | 12 | i = 0; 13 | while (dest[i] != '\0') 14 | i++; 15 | j = 0; 16 | while (src[j] != '\0') 17 | { 18 | dest[i + j] = src[j]; 19 | j++; 20 | } 21 | dest[i + j] = '\0'; 22 | return (dest); 23 | } 24 | 25 | char *ft_strdup(string src) 26 | { 27 | char *new1; 28 | int i; 29 | int size; 30 | 31 | size = 0; 32 | while (src[size]) 33 | ++size; 34 | if (!(new1 = (char *)malloc(sizeof(char) * (size + 2)))) 35 | return (NULL); 36 | i = 0; 37 | while (src[i]) 38 | { 39 | new1[i] = src[i]; 40 | i++; 41 | } 42 | new1[i] = '\0'; 43 | return (new1); 44 | } 45 | 46 | int smallest_alphabet(string a) 47 | { 48 | char min = 'z'; 49 | int min1; 50 | int i = -1; 51 | while (a[++i]) 52 | if (a[i] < a[i + 1]) 53 | return i; 54 | return i; 55 | } 56 | int ft_strcmp(char *s1, string s2) 57 | { 58 | int i; 59 | 60 | i = 0; 61 | while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0') 62 | i++; 63 | return (s1[i] - s2[i]); 64 | } 65 | 66 | void solve() 67 | { 68 | int t , n , min; 69 | cin >> t; 70 | char t1[3]; 71 | string str , temp; 72 | char *rstr; 73 | for (int i = 0; i < t ; i++) 74 | { 75 | cin >> n; 76 | cin >> str; 77 | t1[0] = str[0]; 78 | t1[1] = str[0]; 79 | t1[2] = 0; 80 | if (ft_strcmp(t1, str) <= 0) 81 | { 82 | cout << t1 << endl; 83 | continue ; 84 | } 85 | min = smallest_alphabet(str); 86 | rstr = ft_strdup(str); 87 | rstr[min + 1] = 0; 88 | temp = str.substr(0,min + 1); 89 | reverse(temp.begin(), temp.end()); 90 | cout << rstr << temp<< endl ; 91 | } 92 | 93 | } 94 | int main(void) 95 | { 96 | solve(); 97 | return 0; 98 | } --------------------------------------------------------------------------------