PrintSubStr(string str, int low, int high) { for
Download 96.26 Kb.
|
8-variant Satrdagi eng uzun simmetrik qismini topadigan dastur tuzing. #include using namespace std; void printSubStr(string str, int low, int high) { for (int i = low; i <= high; ++i) cout << str[i]; } int longestPalSubstr(string str) { int n = str.size(); int maxLength = 1, start = 0; for (int i = 0; i < str.length(); i++) { for (int j = i; j < str.length(); j++) { int flag = 1; for (int k = 0; k < (j - i + 1) / 2; k++) if (str[i + k] != str[j - k]) flag = 0; if (flag && (j - i + 1) > maxLength) { start = i; maxLength = j - i + 1; } } } cout << "simmetrik qismi: "; printSubStr(str, start, start + maxLength - 1); return maxLength; } int main() { string str; cout << "Satr kiriting : "; getline(cin, str); longestPalSubstr(str); return 0; } char turidagi A satrdagi har bir soʻzni teng yarmini oʻchiradigan dastur tuzing. #include #include using namespace std; int main() { string satr; cout << "Satrni kiriting " << endl; cin >> satr; size_t n = satr.length(); int s = n / 2; satr.erase(s); cout << satr; return 0; } Download 96.26 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling