Answer the question
In order to leave comments, you need to log in
CLR Windows Form - how to determine if a string contains palindrome words?
The task is simple:
Given a string of characters. Determine if a string contains palindrome words. If there is, then mark each word with a % symbol at the beginning and end of the word (for example, %stomp% ).
The thing is, I can't figure out how to do this for multiple words in a line.
Here is the code, so far for only one word per line.
private: System::Void btn_pal_Click(System::Object^ sender, System::EventArgs^ e) {
if (cb_1->Checked == false && cb_2->Checked == false) {
MessageBox::Show("Выберите способ вывода.", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
return;
}
String^ str = tb_words->Text;
String^ str2 = str;
array <wchar_t>^ mass = tb_words->Text->ToCharArray();
int n = tb_words->Text->Length;
bool palindrom = true;
for (int r = 0; r < mass->Length; r++) {
for (int i = 0; i < (n / 2); i++)
{
if (mass[i] != mass[n - i - 1])
{
palindrom = false;
break;
}
}
}
if (palindrom) {
if ((cb_1->Checked == true) && (cb_2->Checked == false))
{
tb_words->Text = "%" + str + "%";
str = str2;
}
if ((cb_2->Checked == true) && (cb_1->Checked == false)) {
lb_pal->Items->Add("%" + str + "%");
str = str2;
}
if ((cb_1->Checked == true) && (cb_2->Checked == true)) {
tb_words->Text = "%" + str + "%";
lb_pal->Items->Add("%" + str + "%");
str = str2;
}
btn_pal->Enabled = false;
}
}
Answer the question
In order to leave comments, you need to log in
What does WinForms have to do with it? From assignment
Дана строка символов. Определить, есть ли в строке слова-палиндромы.
Если есть, то отметить каждое слово символом % в начале и в конце слова (например, %топот% ).
it is clear that only two super-complicated actions are required from winforms: read a line from a textbox and write the result. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question