Home
О нас
Products
Services
Регистрация
Войти
Поиск
angryfukse
@angryfukse
July 2022
1
36
Report
Написать программу для подсчёта количества вхождений подстроки в строку. (Язык С++)
Please enter comments
Please enter your name.
Please enter the correct email address.
Agree to
terms of service
You must agree before submitting.
Send
Answers & Comments
pacixor
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str, substr;
cout << "String = "; getline(cin, str);
cout << "Substring = "; cin >> substr;
int cnt = 0;
for(int i = 0; i < str.length(); ++i)
if(str[i] == substr[0])
if(str.substr(i, substr.length()) == substr)
{
++cnt;
i += substr.length() - 1;
}
cout << cnt;
return 0;
}
/****************************************************/
Пример:
String = test testHelloWorld testtest1243test
Substring = test
5
2 votes
Thanks 1
More Questions From This User
See All
angryfukse
August 2022 | 0 Ответы
predpolagaetsya chto tekstovyj fajl soderzhit stroki dlinoj ne bolee 80 simvolov45408de01698d2f95a48ddf3456ab1f3 1555
Answer
angryfukse
August 2022 | 0 Ответы
programma vyvodit informaciyu o date rozhdeniya est klass date i unasledovannyj o
Answer
angryfukse
August 2022 | 0 Ответы
napisat programmu kotoraya podschityvaet kolichestvo vvedyonnyh simvolovbukv v t
Answer
angryfukse
July 2022 | 0 Ответы
napisat klass date soderzhashij tri polya den mesyac god s pomoshyu funkcij os
Answer
angryfukse
July 2022 | 0 Ответы
3)-8=0...
Answer
angryfukse
July 2022 | 0 Ответы
v treugolnike abc ugol c raven 90 gradusov vysota ch ravna 3 bh4 najdite co
Answer
angryfukse
July 2022 | 0 Ответы
predpolagaetsya chto tekstovyj fajl soderzhit stroki dlinoj ne bolee 80 simvolov
Answer
angryfukse
July 2022 | 0 Ответы
najti vse korni uravneniya z4 2 2i pri z xiy
Answer
angryfukse
July 2022 | 0 Ответы
postroit oblast na kompleksnoj ploskosti z4 gt 3 z
Answer
angryfukse
July 2022 | 0 Ответы
napisat rekursivnuyu proceduru perevodyashuyu chisla iz odnoj sistemy schisleniya v d
Answer
рекомендуемые вопросы
rarrrrrrrr
August 2022 | 0 Ответы
o chem dolzhny pozabotitsya v pervuyu ochered vzroslye pri organizacionnom vyvoze n
danilarsentev
August 2022 | 0 Ответы
est dva stanka na kotoryh vypuskayut odinakovye zapchasti odin proizvodit a zapcha
myachina8
August 2022 | 0 Ответы
najti po grafiku otnoshenie v3v1 v otvetah napisano 9 no nuzhno reshenie
ydpmn7cn6w
August 2022 | 0 Ответы
Choose the correct preposition: 1.I am fond (out,of,from) literature. 2.where ar...
millermilena658
August 2022 | 0 Ответы
opredelite kak sozdavalas i kto sozdaval arabskoe gosudarstvo v kracii
MrZooM222
August 2022 | 0 Ответы
ch ajtmanov v rasskaze krasnoe yabloko ispolzuet metod rasskaz v rasskaze opi
timobila47
August 2022 | 0 Ответы
kakovo bylo naznachenie kazhdoj iz chastej vizantijskogo hrama pomogite pozhalujsta
ivanyyaremkiv
August 2022 | 0 Ответы
moment. 6....
pozhalujsta8b98a56c0152a07b8f4cbcd89aa2f01e 97513
sarvinozwakirjanova
August 2022 | 0 Ответы
pomogite pozhalusto pzha519d7eb8246a08ab0df06cc59e9dedb 6631
×
Report "Написать программу для подсчёта количества вхождений подстроки в строку. (Язык С..."
Your name
Email
Reason
-Select Reason-
Pornographic
Defamatory
Illegal/Unlawful
Spam
Other Terms Of Service Violation
File a copyright complaint
Description
Helpful Links
О нас
Политика конфиденциальности
Правила и условия
Copyright
Контакты
Helpful Social
Get monthly updates
Submit
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <string>
using namespace std;
int main()
{
string str, substr;
cout << "String = "; getline(cin, str);
cout << "Substring = "; cin >> substr;
int cnt = 0;
for(int i = 0; i < str.length(); ++i)
if(str[i] == substr[0])
if(str.substr(i, substr.length()) == substr)
{
++cnt;
i += substr.length() - 1;
}
cout << cnt;
return 0;
}
/****************************************************/
Пример:
String = test testHelloWorld testtest1243test
Substring = test
5