Нужно найти количество букв о в 2 слове фразы, которая состоит из 3 слов. Помогите написать часть кода. Вот заготовка:
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include
using namespace std;
void main()
{
char string[100];
char *p;
int K;
int N1,N2,M=0;
int z;
cout«"vvedi stroky\n"; //VVOD
cin.getline(string,100);
K=strlen(string);
for (int z=0;z<K;z++) //poisk imeni
if (string[z] == ' ')
{
M=M++;
if (M==1) N1=z;
if (M==2) N2=z;
}
for ( z=N1; z<N2;z++)
{
cout«string[z];
}
system("pause");
}
Другие языки программирования и технологии
C++ сторки
#include "stdafx.h"
#include "iostream" // не в кавычках, а в < >
using namespace std;
int main()
{
char str[100];
int amount = 0;
setlocale(0, "rus");
cout << "Введите фразу латиницей: ";
cin.getline(str, 100);
char * explode = strtok(str, " ");
explode = strtok(NULL, " ");
for(int i = 0; i < strlen(explode); i++)
{
if(explode[i] == 'O' || explode[i] == 'o')
amount++;
}
cout << "Всего \"O\" во второй фразе = " << amount << "\n";
system("pause");
}
#include "iostream" // не в кавычках, а в < >
using namespace std;
int main()
{
char str[100];
int amount = 0;
setlocale(0, "rus");
cout << "Введите фразу латиницей: ";
cin.getline(str, 100);
char * explode = strtok(str, " ");
explode = strtok(NULL, " ");
for(int i = 0; i < strlen(explode); i++)
{
if(explode[i] == 'O' || explode[i] == 'o')
amount++;
}
cout << "Всего \"O\" во второй фразе = " << amount << "\n";
system("pause");
}
Ну тогда уж если strtok и плевать на многопоточность ^___^. Если юзать C++ 11, то можно было бы чуть изящнее.
#include < iostream >
#include < algorithm >
#include < cstring >
using namespace std;
bool isO (char c) { return toupper(c)=='O'; }
int main (int argc, char *argv[])
{
const char cDelimiters[] = " ,.;?!:";
string text = "Hello woOorld again!";
char * token = strtok((char*)text.c_str(), cDelimiters);
if (token)
if (token = strtok(NULL, cDelimiters)) {
cout <<
"Word: " << token << endl <<
"Count: " << count_if(token, token + strlen(token), isO) << endl;
}
return 0;
}
#include < iostream >
#include < algorithm >
#include < cstring >
using namespace std;
bool isO (char c) { return toupper(c)=='O'; }
int main (int argc, char *argv[])
{
const char cDelimiters[] = " ,.;?!:";
string text = "Hello woOorld again!";
char * token = strtok((char*)text.c_str(), cDelimiters);
if (token)
if (token = strtok(NULL, cDelimiters)) {
cout <<
"Word: " << token << endl <<
"Count: " << count_if(token, token + strlen(token), isO) << endl;
}
return 0;
}
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include
using namespace std;
void main()
{
int y=0;
char string[100];
char *p;
int K;
int N1,N2,M=0;
int z;
cout«"vvedi stroky\n"; //VVOD
cin.getline(string,100);
K=strlen(string);
for (int z=0;z<K;z++) //poisk imeni
if (string[z] == ' ')
{
M=M++;
if (M==1) N1=z;
if (M==2) N2=z;
}
for ( z=N1; z<N2;z++)
{
cout«string[z];
if (string[z]=='O' || string[z]=='o')
{
y=y++;
}
}
cout<<"kolichestvo bykv o "<< y;
}
}
system("pause");
}
#include "iostream"
#include "conio.h"
#include
using namespace std;
void main()
{
int y=0;
char string[100];
char *p;
int K;
int N1,N2,M=0;
int z;
cout«"vvedi stroky\n"; //VVOD
cin.getline(string,100);
K=strlen(string);
for (int z=0;z<K;z++) //poisk imeni
if (string[z] == ' ')
{
M=M++;
if (M==1) N1=z;
if (M==2) N2=z;
}
for ( z=N1; z<N2;z++)
{
cout«string[z];
if (string[z]=='O' || string[z]=='o')
{
y=y++;
}
}
cout<<"kolichestvo bykv o "<< y;
}
}
system("pause");
}
Похожие вопросы
- Учусь програмировать на C++ по книге "C++ для чайников".Проблема.
- Зачем нужен C++, если есть C?
- Помогите срочно C#
- Помогите исправить ошибку в программе (c++).
- Ещё тупой вопрос по C++ :)
- Почему многие отдают предпочтение C++ а не C# ?
- Учу C++! Уже знаю: типы данных, циклы. условия, привидения и т. д учу 5дней. вот программа! Как норм за 5 дней?
- Как в C++ приравнять переменную и текст? А то такую запись нельзя. А без этого задачу не решить
- Язык программирования C.
- Проверти правильность программы на C++