Modifies the default numeric base for integer I/O.
я уже на третьем телефоне>
ui->actionSwelab_Alfa_1
ui->actionSwelab_Alfa_2
?#include <stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int search(const char base_string[], const char substr[])
{
int string_length = strlen( base_string );
int substr_lenght = strlen( substr );
int diff = string_length - substr_lenght;
bool find = false;
bool end = false;
int current = 0;
while ( (!end) && (!find) )
{
int counter = 0;
while ( ( base_string[current+counter] == substr [counter] ) && ( counter < substr_lenght) ) counter++;
if (counter == substr_lenght) find=true;
if ( !find ) current++;
if ( current > diff ) { end =true; current=-1; }
}
return current;
}
int main()
{
cout << search("badbarrar", "bar");
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int temp=0;
vector<int> data;
while(cin>>temp) data.push_back(temp);
int next=0;
for (int s=0; s<data.size()-1; ++s)
{
for(int current=0; current<data.size()-1; ++current)
{
next=current+1;
if(data[current]>data[next])
{
temp=data[current];
data[current]=data[next];
data[next]=temp;
}
}
}
return 0;
}
В векторе у меня 10 ячеек, соответственно, когда программа доходит до v[i(то есть 10)], она проверит, больше ли последняя ячейка следующей ячейки (v[i+1(то есть 11)], но беда в том, что ячейки 11 не существует.
Поэтому я добавил это условие, которое проверяет, так скажем, существует ли следующая ячейка, а если не существует, то проверить, больше ли предыдущее значение ячейки, чем последнее значение ячейки, и выполнить в случае необходимости их перестановку.
if(v[i]>v[i+1]) {
все равно выполнится.
Ну вы чересчур строги к новому и явно юному адепту. Спугнете. Вы еще намекните ему, что надо будет осилить более 3000 страниц стандарта. Так он сразу сбежит.