Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <regex>
- using namespace std;
- int N;//the size of matrix.
- char Matrix[50][50];
- char str[50]={'0'};//store possible string.
- char* create_string( char (*Matrix)[50], int N, int row, int col, char *str);
- int main()
- {
- int i,j;
- cin >> N;
- for(i=0;i<N;i++){
- for(j=0;j<N;j++){
- cin >> Matrix[i][j];
- }
- }
- //start from every point to search the matching string.
- for(i=0 ;i<N; i++){
- for(j=0 ;j<N; j++){
- create_string(Matrix,N,i,j,str);
- }
- }
- return 0;
- }
- char* create_string( char (*Matrix)[50], int N, int row, int col, char *str){
- //recursion to find valid string. start from Matix[i][j].
- static int i=0;
- //basic case.
- if(row+1==N && col)
- //recursive case.
- if(row+1<N){
- str[i] = Matrix[row][col];
- i++;
- create_string(Matrix,N,row+1,col,str);
- }
- if(col+1<N){
- str[i] = Matrix[row][col];
- i++;
- create_string(Matrix,N,row,col+1,str);
- }
- if(row-1<=0){
- str[i] = Matrix[row][col];
- i++;
- create_string(Matrix,N,row-1,col,str);
- }
- if(col-1<=0){
- str[i] = Matrix[row][col];
- i++;
- create_string(Matrix,N,row,col-1,str);
- }
- //once we find one, print out directly.
- //then sort this string to print with correct form(vowel in front of consonant.)
- return str;
- }
- void valid(char *str){
- regex expression("[^aeiou][aeiou]+([^aeiou][aeiou]+)+[^aeiou]");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement