AndrewRadkovich
BAN USER
#include <iostream>
#include <string>
using namespace std;
void remove(string & str, int index)
{
for(int i = index; i < str.size(); i++)
str[i] = str[i + 1];
}
string removeDeplicated(string str)
{
for(int i = 0; i < str.size(); i++)
for(int j = i + 1; j < str.size(); j++)
if(str[i] == str[j])
remove(str, j);
return str;
}
int main()
{
cout << removeDeplicated("abracadabra") << endl;
return 0;
}
#include <string.h>
#include <stdio.h>
const int N = 5,
M = 4;
int checkNeighbor(char arr[M][N], int i, int j, char str[], int next)
{
if(next == strlen(str)) return 1;
int counter = 0;
if(arr[i - 1][j] == str[next] && i - 1 >= 0)
counter += checkNeighbor(arr, i - 1, j, str, next + 1);
if(arr[i + 1][j] == str[next] && i + 1 < M)
counter += checkNeighbor(arr, i + 1, j, str, next + 1);
if(arr[i][j - 1] == str[next] && j - 1 >= 0)
counter += checkNeighbor(arr, i, j - 1, str, next + 1);
if(arr[i][j + 1] == str[next] && j + 1 < N)
counter += checkNeighbor(arr, i, j + 1, str, next + 1);
return counter;
}
int main()
{
char arr[M][N] = {'S', 'N', 'B', 'S', 'N',
'B', 'A', 'K', 'E', 'A',
'B', 'K', 'B', 'B', 'K',
'S', 'E', 'B', 'S', 'E'},
str[] = "SNAKES";
int counter = 0;
for(int i = 0; i < M; i++)
for(int j = 0; j < N; j++)
if(arr[i][j] == str[0])
counter += checkNeighbor(arr, i, j, str, 1);
printf("%d\n", counter);
return 0;
}
#include <list>
#include <iostream>
using namespace std;
const int N = 3;
void checkNeighbour(int arr[N][N], int i, int j, list<int> & snake)
{
if(arr[i + 1][j] - arr[i][j] == 1 && i + 1 < N)
{
snake.push_back(arr[i + 1][j]);
checkNeighbour(arr, i + 1, j, snake);
}
if(arr[i - 1][j] - arr[i][j] == 1 && i - 1 >= 0)
{
snake.push_back(arr[i - 1][j]);
checkNeighbour(arr, i - 1, j, snake);
}
if(arr[i][j - 1] - arr[i][j] == 1 && j - 1 >= 0)
{
snake.push_back(arr[i][j - 1]);
checkNeighbour(arr, i, j - 1, snake);
}
if(arr[i][j + 1] - arr[i][j] == 1 && j + 1 < N)
{
snake.push_back(arr[i][j + 1]);
checkNeighbour(arr, i, j + 1, snake);
}
return;
}
int main()
{
int arr[N][N] = {1, 5, 9, 2, 3, 8, 4, 6, 7}, max_length = 0;
list<list<int>> list_of_snakes;
list<int> snake, //final snake
t_snake; //temporary snake
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
t_snake.push_back(arr[i][j]);
checkNeighbour(arr, i, j, t_snake);
if(t_snake.size() == 1)
{
t_snake.clear();
continue;
}
else list_of_snakes.push_back(t_snake);
t_snake.clear();
}
}
for(list<list<int>>::iterator i = list_of_snakes.begin(); i != list_of_snakes.end(); i++)
{
if(max_length < i->size())
{
max_length = i->size();
snake = *i;
}
}
for(list<int>::iterator i = snake.begin(); i != snake.end(); i++)
cout << *i << " ";
return 0;
}
public static String longPrefix(String str)
{
String[] words = str.split(" ");
for(int j = 0; ; j++)
{
for(int i = 1; i < words.length; i++)
{
if ( words[0].charAt(j) != words[i].charAt(j))
return words[0].substring(0, j);
}
}
}
RepPacheTanley, Associate at Adobe
Hi , I am Conference service coordinator for the KB Toys company. I Build and maintain relationships with meeting planners and ...
RepErmanStern, Applications Developer at ADP
I am Erman . I am metal finishing-, plating- and coating-machine operators operate and monitor equipment which finishes, plates and coats ...
RepJanie Margreta, Android Engineer at Achieve Internet
JanieMargreta works as a plant operator, an employee who supervises the operation of an industrial plant. Where I have to ...
RepFanieGoode, Consultant at Achieve Internet
I am a Media Library Assistant that provides integrated support for two popular “Multi Language/ Multilingual/ Internationalization” plugins; WPML and ...
RepNorinaKen, iOS Developer at ASU
Norina, a certified ENP and Emergency Medical Dispatcher with 7 + years of work experience got the opportunity to join the ...
- AndrewRadkovich August 04, 2014