https://youtu.be/8jLOx1hD3_o?si=50jxQOEep2rWiI5T кто-то просил выложить видео сюда,это очень класное видео которое охватывает все
C++ Chanel
Очень интересная задача,сегодня была на олимпиаде: дается числа m и n: m ширина n высота вывести рисунок,например: m=4 n=6 “x..x” “.xx.” “.xx.” “x..x” “.xx.” “.xx.” Решение как всегда кину сегодня вечером Накидайте 🔥🔥🔥 если вам интересный такой формат
Решение(в коменты кидали на пайтоне)
#include <iostream>
using namespace std;
int main() {
int m, n;
cin >> n >> m;
string column;
int left = 0;
int right = m - 1;
for (int i = 0; i < m; i++)column += '.';
for (int i = 0; i < n; i++) {
string copyColumn = column;
for (int j = 0; j < m; j++) {
if (j == left)copyColumn[left] = 'x';
if (j == right)copyColumn[right] = 'x';
}
right--;
left++;
if (right == 0)right = m-1;
if (left == m-1)left = 0;
cout << copyColumn << endl;
}
return 0;
}
👏1
Интересная задача:
https://leetcode.com/problems/reverse-integer/
Как всегда решение кину чуть-чуть позже
https://leetcode.com/problems/reverse-integer/
Как всегда решение кину чуть-чуть позже
LeetCode
Reverse Integer - LeetCode
Can you solve this real interview question? Reverse Integer - Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
Assume the environment…
Assume the environment…
Будет ли вам интересно если я буду выставлять про микроконтроллеры?(Ведь это тоже С++)
Anonymous Poll
86%
Да
14%
Нет
C++ Chanel
Интересная задача: https://leetcode.com/problems/reverse-integer/ Как всегда решение кину чуть-чуть позже
Решение:
class Solution {
public:
int reverse(long x) {
long result = 0;
bool plural = x>0;
if(!plural)x*=-1;
while(x>0){
result+=x%10*10;
result*=10;
x/=10;
}
result/=100;
if(result>pow(2,31)-1||result<-pow(2,31))return 0;
if(!plural)return result*-1;
return result;
}
};
Задача на сегодня:
https://leetcode.com/problems/largest-3-same-digit-number-in-string/
Решение кину вечером
https://leetcode.com/problems/largest-3-same-digit-number-in-string/
Решение кину вечером
LeetCode
Largest 3-Same-Digit Number in String - LeetCode
Can you solve this real interview question? Largest 3-Same-Digit Number in String - You are given a string num representing a large integer. An integer is good if it meets the following conditions:
* It is a substring of num with length 3.
* It consists…
* It is a substring of num with length 3.
* It consists…
Решение:
class Solution {
public:
string largestGoodInteger(string num) {
if(num.size()==3){
if(num[0] == num[1] && num[2] == num[0])return num;
}
vector<string> res;
string temp;
temp += num[0];
string result = "-1";
for(int i = 0;i<num.size()-1;i++){
if(num[i] == num[i+1]){
temp += num[i+1];
if(temp.size() == 3 && stoi(temp)>stoi(result))result = temp;
}
else temp = num[i+1];
}
if(result == "-1")return "";
return result;
}
};
👍2
Задача на сегодня:
https://leetcode.com/problems/buddy-strings/
https://leetcode.com/problems/buddy-strings/
LeetCode
Buddy Strings - LeetCode
Can you solve this real interview question? Buddy Strings - Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false.
Swapping letters is defined as taking two indices i and j (0-indexed)…
Swapping letters is defined as taking two indices i and j (0-indexed)…
Что такое тернарный оператор и как его использовать ?
По факту тернарный оператор это тоже самое что и if else.Но с другим синтаксисом.Например:
Так мы написали используя if,else.А теперь с тернарным оператором:
По факту тернарный оператор это тоже самое что и if else.Но с другим синтаксисом.Например:
int temperature = 20;
if(temperature>0)cout<<"HOT";
else cout<<"COLD";
Так мы написали используя if,else.А теперь с тернарным оператором:
int temperature = 20;
temperature>0?cout<<"HOT" : "COLD";
👍7
C++ Chanel
Задача на сегодня: https://leetcode.com/problems/buddy-strings/
Решение:
class Solution {
public:
bool buddyStrings(string s, string goal) {
if(s == goal)return false;
sort(s.begin(),s.end());
sort(goal.begin(),goal.end());
if(s.size()!=goal.size())return false;
for(int i = 0;i<s.size();i++){
if(s[i]!=goal[i])return false;
}
return true;
}
};
👍1
Задача на сегодня:
https://leetcode.com/problems/container-with-most-water/
https://leetcode.com/problems/container-with-most-water/
LeetCode
Container With Most Water - LeetCode
Can you solve this real interview question? Container With Most Water - You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Find two lines that together…
Find two lines that together…
👍1
Решение:
class Solution {
public:
int maxArea(vector<int>& height) {
int left = 0;
int right = height.size()-1;
int result = 0;
for(;left<right;){
int temp = min(height[left],height[right])*(right-left);
result = max(result,temp);
if(height[left] < height[right])
left++;
else right--;
}
return result;
}
};
👍2
C++ Chanel
Задача на сегодня: https://leetcode.com/problems/longest-substring-without-repeating-characters/
Решение:
объяснение скину чуть-чуть позже
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int result = 0;
for(int i = 0;i<s.size();i++){
int counter = 0;
unordered_set<char> chae;
for(int j = i;j<s.size();j++){
counter++;
chae.insert(s[j]);
if(chae.size()==counter && result<counter)result = counter;
if(chae.size()!=counter) break;
}
}
return result;
}
};
объяснение скину чуть-чуть позже
C++ Chanel
Решение: class Solution { public: int lengthOfLongestSubstring(string s) { int result = 0; for(int i = 0;i<s.size();i++){ int counter = 0; unordered_set<char> chae; for(int j = i;j<s.size();j++){ …
сначала я создаю переменную результат которая и будет ответом на задачу,после этого я создаю цикл который проходит по всем буквам строки,создаю counter которая будет равна нулю каждый пройденный цикл.Дальше unordered_set(кто не знает это ассоциативный контейнер который не имеет одинаковых объектов например он не может иметь два 's' или два одинаковых числа)и потом сравниваю если кол-во элементов в сете равен нашему счету то мы делаем проверку,больше ли наш результат чем наш счет(counter),а если кол-во элементов не равно счету-выходим из первого цикла
Про unordered_set: https://runebook.dev/ru/docs/cpp/container/unordered_set
Если что-то непонятно-спрашивайте в комментариях.
Про unordered_set: https://runebook.dev/ru/docs/cpp/container/unordered_set
Если что-то непонятно-спрашивайте в комментариях.
👍1
Раньше создавал много сайтов на заказ,возможно кому нибудь интересно.
Если будет много реакций выложу исходники наработок сверху
Если будет много реакций выложу исходники наработок сверху
❤6