1) задача была посчитать колво символов
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cctype>
int getRandomNumber(int min, int max)
{
static const double fraction = 1.0 / (static_cast<double>(RAND_MAX) + 1.0);
return static_cast<int>(rand() * fraction * (max - min + 1) + min);
}
using namespace std;
int main() {
string a;
getline(cin, a);
int punktCounter = 0;
int amperSandCounter = 0;
int gCounter = 0;
for(int i = 0; i<a.length(); ++i) {
if(ispunct(a[i])) {
++punktCounter;
if(a[i]=='&') {
++amperSandCounter;
if(a[i]=='g'||a[i]=='G') {
++gCounter;
cout << "Simvolov v tekste: ";
cout << a.length();
cout << "Punkts: " << punktCounter-amperSandCounter << endl;
cout << "'&': " << amperSandCounter << endl;
cout << "'G': " << gCounter;
2) #include <iostream>
int counter = 0;
for(int i = 0; i < a.length(); ++i) {
if(a[i]==':') {
break;
if(i<a.length()-2) {
if(a[i]=='b'&&a[i+1]=='a'&&a[i+2]=='y') {
++counter;
cout << endl << counter;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
1) задача была посчитать колво символов
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cctype>
int getRandomNumber(int min, int max)
{
static const double fraction = 1.0 / (static_cast<double>(RAND_MAX) + 1.0);
return static_cast<int>(rand() * fraction * (max - min + 1) + min);
}
using namespace std;
int main() {
string a;
getline(cin, a);
int punktCounter = 0;
int amperSandCounter = 0;
int gCounter = 0;
for(int i = 0; i<a.length(); ++i) {
if(ispunct(a[i])) {
++punktCounter;
}
if(a[i]=='&') {
++amperSandCounter;
}
if(a[i]=='g'||a[i]=='G') {
++gCounter;
}
}
cout << "Simvolov v tekste: ";
cout << a.length();
cout << "Punkts: " << punktCounter-amperSandCounter << endl;
cout << "'&': " << amperSandCounter << endl;
cout << "'G': " << gCounter;
}
2) #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
string a;
int counter = 0;
getline(cin, a);
for(int i = 0; i < a.length(); ++i) {
if(a[i]==':') {
break;
}
if(i<a.length()-2) {
if(a[i]=='b'&&a[i+1]=='a'&&a[i+2]=='y') {
++counter;
}
}
}
cout << endl << counter;
}