Write a C++ program to concat two given strings. If the given strings have different length remove the characters from the longer string
- برمجة سي بلس بلس
- برمجة
- 2021-05-11
- MarwaMohammed
الأجوبة
#include <iostream>
using namespace std;
string test(string s1, string s2)
{
if (s1.length() < s2.length())
{
return s1 + s2.substr(s2.length() - s1.length());
}
else if (s1.length() > s2.length())
{
return s1.substr(s1.length() - s2.length()) + s2;
}
else
{
return s1 + s2;
}
}
int main()
{
cout << test("abc", "abcd") << endl;
cout << test("Python", "Python") << endl;
cout << test("JS", "Python") << endl;
return 0;
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
