[Arabic] Implement Functions With C++ #11 - Trim String
Вставка
- Опубліковано 26 вер 2024
- Paid Courses
www.elzero.cou...
Trim String
elzero.org/imp...
The Implement Functions Playlist
• Implement Functions Wi...
Fundamentals of Programming With C++
• Fundamentals Of Progra...
Join Premium Members
elzero.org/join/
Telegram Channel For The Course:
t.me/ElzeroCPl...
لازم تتعلم ازاي تختصر الحل لو ينفع يختصر وتعمل حلك الخاص
علشان تعرف انت بتتطور ولالا وبتتعلم حاجة جديدة ولالا
حل حضرتك ممتاز الله اكبر افكار رائعه
ولا ليا ف البرمجة ولا اي من مشتقاتها واما ف مجال طبي اصلا شوفت بودكاستس ليك مع ابو زيد و د. ايهاب بعدها رحت لبلاي ليست رحلتي مع الحياة انت مش هتتخيل السلسلة دي غيرت طريقة تفكير ازاي و علمتني الصبر علي الظروف و الابتلاء وانه رزقك مكتوب وانت بس تسعي
اتمني يا بشمهندس تثبت فيديو لو حتي ف الشهر عن نصائح عموما ف الحياة او قناة منفصلة
وبارك الله فيك ❤
عنده قناة منفصلة بينزل عليها مواضيع مختلفة Elzero tube
ربنا يبارك في حضرتك يا هندسه ✨❤️
جزاك الله خيرا
جزاك الله عنا خير جزاء استاذ اسامه
بارك الله فيك ❤
يا باشمهندس اسامة انا قلتله ان لو direction يساوي left يبدأ يعد الهاشز و لو تساوي right يعدي الهاشز بالعكس فهل دا هيكون احسن من حيث time complexity لانه مش مطلوب منه يعد عدد الهاشز لو direction مش زي اللي في condition ؟
جزاك الله خيرا حقييقي حجات بتخلينا نفكر
وعندي سؤال لو عندي حلين بطريقتين مختلفتين اعرف ايه فيهم احسن ازاي؟
و عليكم السلام ورحمة الله وبركاته
عايزين كورس network ي بشمهندس
السلام عليكم
string Trim_String(string st, string direction = "All", char ch = ' ')
{
int fisrtcharcount = 0;
int lastcharcount = st.length()-1;
string result;
if (direction == "Left" || direction == "All")
for (int i = 0; i = 0; i--)
if (st[i] == ch)
lastcharcount--;
else
break;
for (int i = fisrtcharcount; i
انا بالنسبالي لو هنفذ حاجة زي دي في الغالب هستعمل enum و في كود الإختيارات هادمج التلاتة في بعض😅
يعني مثلا:
enum direction { all, right, left };
string trim_string(string str, direction d=direction::all, char ch=' ') {
size_t first = 0, last = str.size() - 1;
while (d != right && str[first] == ch) first++;
while (d != left && str[last] == ch) last--;
return string(str.begin() + first, str.begin() + last);
}
تعديل: انا كتبت الكود في تعليق اليوتيوب كتحدي لنفسي و الحمد لله مغلطتش كتير فيه غلطتين بس😅
واحدة ممكن تحصل في كلمة right, left فنخليها أحسن direction::right, direction::left
و التانية في آخر سطر المفروض تقوله last + 1 مش last بس لأنه المفروض تعدي آخر الstring مش تقف عنده
string trim_string(string str , string dirction ="All",char ch =' '){
string resulte ;
int start = 0, end =str.size();
if(dirction == "All"){
for(int i =0;i
string trim_string(string st, string direction = "All", char ch = ' ')
{
string result;
for (int i = 0; i < st.size(); i++)
{
if (direction == "All" && st[i] != ch) result += st[i];
else if (direction == "Left" && st[i] != ch) for (; i < st.size(); i++) result += st[i];
else if (direction == "Right")
{
result += st[i];
if (st[i] != ch && st[i + 1] == ch) break;
}
}
return result;
} رايك يبروفيسور
#include
using namespace std ;
string Trim_String(string str , string Direction = "All" , char ch = ' ')
{
string result ;
int First_Chars = 0 ;
int Last_Chars = 0 ;
for(auto s : str)
{
if(s == ch)
First_Chars += 1 ;
else
break ;
}
for(int i = str.length() - 1 ; i >= 0 ; i--)
{
if(str[i] == ch)
Last_Chars += 1 ;
else
break ;
}
for(int i = 0 ; i < str.size() ; i++)
{
if(Direction == "All")
{
if (i > First_Chars - 1 && i < str.length() - Last_Chars ) result.push_back(str[i]) ;
} else if (Direction == "Left")
{
if (i >= First_Chars && i < str.size()) result.push_back(str[i]) ;
}else
{
if(i >= 0 && i < str.length() - Last_Chars ) result.push_back(str[i]) ;
}
}
return result ;
}
int main()
{
cout
string trim_string(string st, string direction = "All", char ch = ' ')
{
string result;
int fristcount = 0, seccount = 0;
for (int i = 0; i < st.length() / 2; i++)
if (st[i] == ch) fristcount++;
for (int i = st.length() - 1; i >= st.length() / 2; i--)
if (st[i] == ch) seccount++;
if (direction == "All")
{
for (int i = fristcount; i < st.length() - seccount; i++)
result += st[i];
}
else if (direction == "Left")
{
for (int i = fristcount; i < st.length(); i++)
result += st[i];
}
else if(direction == "Right")
{
for (int i = 0; i < st.length() - seccount; i++)
result += st[i];
}
return result;
}
void main()
{
cout
حلها في الفيديو رقم كم؟
string trim_string(string str , char trim , string dir = "All" )
{
int si = str.length() / 2 ;
if(dir == "left")// tarekek###
{
auto newEnd = remove(str.begin(), str.end(), trim);
str.erase(newEnd, str.end()- si);
}
else if(dir == "right") // ###tarek
{
str.erase(remove(str.begin() + si, str.end() , trim ), str.end());
}
else // ###tarek###
{
str.erase(remove(str.begin(), str.end(), trim ), str.end());
}
return str ;
}
❤
#include
using namespace std;
string TrimLeft(string name)
{
for (int i = 0; i < name.size(); i++)
{
if (name[i] != '#')
{
return name.substr(i, name.size() - i);
}
}
return "";
}
string TrimRight(string name)
{
for (int i = name.size() - 1; i >= 0; i--)
{
if (name[i] != '#')
{
return name.substr(0, i + 1);
}
}
return "";
}
string Trim(string name)
{
return TrimRight(TrimLeft(name));
}
int main()
{
string name = "#########mahmoud elsayed#########";
cout
#include
using namespace std;
string Trim(string name, string direction = "All", char seperator = ' ')
{
string result = "";
short FirstCharCount = 0;
short LastCharCount = 0;
for (int i = 0; i < name.length(); i++)
{
if (name[i] == seperator)
FirstCharCount++;
else
break;
}
for (int i = name.length() - 1; i >= 0; i--)
{
if (name[i] == seperator)
LastCharCount++;
else
break;
}
if (direction == "Left")
for (int i = FirstCharCount; i < name.length(); i++)
result += name[i];
else if (direction == "Right")
for (int i = 0; i < name.length() - LastCharCount; i++)
result += name[i];
else if (direction == "All")
for (int i = FirstCharCount; i < name.length() - LastCharCount; i++)
result += name[i];
return result;
}
int main()
{
string name = "#########mahmoud elsayed#########";
cout
string trim_string(string st, string direction = "All", char ch = ' ')
{
string result = "";
if (direction == "All") for (int i = 0; i < st.length(); i++) if (st[i] != ch) result += st[i];
if (direction == "Right")
{
for (int i = st.length() - 1; i >= 0; i--)
{
if (st[i] != ch)
{
for (int j = 0; j
جزاك الله خيرا
❤
اي حد بيذاكر الكورس من البداية وفاهم اللى فات يا ريت يكلمنى ابعتله الواتس بتاعى عشان محتاج افهم حجات كتير وجزاكم الله خيراً🩵🩵
تفضل