Write a C++ program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string

Sample Output:

Phon
ytade
jsues

الأجوبة

#include <iostream>
using namespace std;

string test(string str)
        {
            return str.substr(1, 2)=="yt" ? str.erase(1, 2) : str;
        }
        
int main() 
 {
  cout << test("Python") << endl;  
  cout << test("ytade") << endl;  
  cout << test("jsues") << endl;  
  return 0;    
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...