Int findDoubleOccurrences(const std:: string& text, char target) {


Download 8.8 Kb.
Sana19.06.2023
Hajmi8.8 Kb.
#1608085
Bog'liq
19-laboratoriya Qodirov Quvondiq


2)#include
#include

int findDoubleOccurrences(const std::string& text, char target) {


int count = 0;
bool foundOnce = false;

for (int i = 0; i < text.length(); i++) {


if (text[i] == target) {
if (foundOnce) {
return i + 1;
} else {
foundOnce = true;
}
}
}

return 0;


}

int main() {


std::string S;
char target = 'a';

std::cout << "Matnni kiriting: ";


std::getline(std::cin, S);

int result = findDoubleOccurrences(S, target);

if (result == 0) {
std::cout << "Natija: 0 (Kelmaydi)\n";
} else {
std::cout << "Natija: " << result << std::endl;
}

return 0;


}
3)#include
#include

bool isPalindrome(const std::string& text) {


int left = 0;
int right = text.length() - 1;

while (left < right) {


if (text[left] != text[right]) {
return false;
}

left++;
right--;


}

return true;


}

int main() {


std::string text;

std::cout << "Satrni kiriting: ";


std::getline(std::cin, text);

if (isPalindrome(text)) {


std::cout << "Bu palindrom satr.\n";
} else {
std::cout << "Bu palindrom satr emas.\n";
}

return 0;


}
4)#include
#include

int countDotsAndQuotes(const std::string& text) {


std::string cleanedText = "";

for (char c : text) {


if (c != '.' && c != '\'') {
cleanedText += c;
}
}

int count = cleanedText.length();


return count;
}

int main() {


std::string text;

std::cout << "Matnni kiriting: ";


std::getline(std::cin, text);

int count = countDotsAndQuotes(text);

std::cout << "Belgilar soni: " << count << std::endl;

return 0;


}
5)#include
#include
#include

bool checkBracketsBalance(const std::string& text) {


std::stack bracketsStack;

for (char c : text) {


if (c == '(') {
bracketsStack.push(c);
} else if (c == ')') {
if (bracketsStack.empty()) {
return false;
}
bracketsStack.pop();
}
}

return bracketsStack.empty();


}

int main() {


std::string text;

std::cout << "Matnni kiriting: ";


std::getline(std::cin, text);

if (checkBracketsBalance(text)) {


std::cout << "Ochildan qavslar va yopilgan qavslar nisbati mos.\n";
} else {
std::cout << "Ochildan qavslar va yopilgan qavslar nisbati mos emas.\n";
}

return 0;


}
11)#include
#include

void removeAbedGroup(std::string& text) {


std::string pattern = "abed";
std::size_t pos;

while ((pos = text.find(pattern)) != std::string::npos) {


text.erase(pos, pattern.length());
}
}

int main() {


std::string S;

std::cout << "Matnni kiriting: ";


std::getline(std::cin, S);

removeAbedGroup(S);

std::cout << "Natija: " << S << std::endl;

return 0;


}
12)#include
#include

int calculateDigitSum(const std::string& text) {


int sum = 0;

for (char c : text) {


if (isdigit(c)) {
sum += (c - '0');
}
}

return sum;


}

int main() {


std::string S;

std::cout << "Matnni kiriting: ";


std::getline(std::cin, S);

int sum = calculateDigitSum(S);

std::cout << "Raqamlar yig'indisi: " << sum << std::endl;

return 0;


}

Download 8.8 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling