//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ if (start==-1) return 0; if (str[start] == str[end]) return 1 + count_pairs(str, len, start - 1, end - 1); else return count_pairs(str, len, start - 1, end - 1); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ if (str==NULL||len<=2) return 0; if (str[start] == str[start + 2]) return 1 + count_pairs(str, len - 1, start + 1, end); else return count_pairs(str, len - 1, start + 1, end); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ if (len < end) return 0; //return 0 when reached end of string else if (str[start] == str[end]) return 1 + count_pairs(str, len, start + 1, end + 1);//adding 1 for each match else return count_pairs(str, len, start + 1, end + 1); //this shows no match }
int count_pairs_wrapper(char *str,int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . int c; if (len <= 0) return 0; else return count_pairs(str, len, 0, 2, 0) + count_pairs(str, len, 1, 3, 0); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end, int count){ if (end > len - 1) return count; else if (*(str + start) == *(str + end)) return count_pairs(str, len, end, end + 2, ++count); else return count_pairs(str, len, end, end + 2, count); //abababababxxxyyy }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ int count; if (end >= len){ return 0; } if (str[start] == str[end]) count = 1 + count_pairs(str, len, start + 1, end + 1); else count = 0 + count_pairs(str, len, start + 1, end + 1); return count; }
int count_pairs(char *str, int len, int start, int end) { if (end >= len) return 0; if (str[start] == str[end]) { return 1 + count_pairs(str, len, start + 1, end + 1); } else return count_pairs(str, len, start + 1, end + 1); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ if (start + 2 == end){ if (str[start] == str[start + 2]) return 1; else return 0; } if (str[start] == str[start + 2] && start + 2 <= end) return (1 + count_pairs(str, len, start + 1, end)); else if (start + 2 <= end) return (0 + count_pairs(str, len, start + 1, end)); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ //static int count = 0; if (end >= len ){ return 0; } else{ if (str[start] == str[end]){ return 1 + count_pairs(str, len, start + 1, end + 1); //printf("\n chr1-%c chr2-%c count-%d start-%d end-%d", str[start], str[end], count, start, end); } return count_pairs(str, len, start + 1, end + 1); } }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start){ if ((start + 2) >= len) { return 0; } else { if (str[start] == str[start + 2]) return (1 + count_pairs(str, len, start + 1)); else return count_pairs(str, len, start + 1); } return 0; }
int count_pairs_wrapper(char *str,int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . int i, k; i = 0; k=count_pairs(str, len, i, i + 2); return k; }
int main(void) { time_t t; int val, ans[7], sumof, ret; srand((int) time(&t)); while (1) { for (val=0; val<6; val++) { ans[val] = (rand() % 6 + 1); write(ans[val]); } count_pairs(ans); sumof = count(ans); printf("Sum of all dices: %i\n", sumof); ret = read_input(); if (ret == 1) { continue; } else { break; } } return 0; }
int count_pairs_wrapper(char *str,int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . if (str==NULL||len<=2) return 0; return count_pairs(str, len, 0, 0); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start,int end){ if (end == len){ return 0; } else{ int count = 0; if (str[start] == str[end]){ count = count + 1 + count_pairs(str, len, start + 1, end + 1); return count; } else{ count = count + count_pairs(str, len, start + 1, end + 1); } return count; } }
int count_pairs_wrapper(char *str,int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . if (len < 3){ return 0; } return count_pairs(str, len, 0, 2); }
int count_pairs_wrapper(char *str, int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . int count = 0; int start = 0; int res = count_pairs(str, start, len, count); return res; }
int count_pairs_wrapper(char *str,int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . if (len > 2) return count_pairs(str, len, len-3, len-1); else return 0; }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ if (end == len - 1){ if (str[start] == str[end]){ return 1; } else{ return 0; } } else{ if (str[start] == str[end]){ return 1 + count_pairs(str, len, start + 1, end + 1); } else{ return count_pairs(str, len, start + 1, end + 1); } } }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ int count = 0; if (end >= len) return 0; if (str[start] == str[end]){ count = count + 1; } return count + count_pairs(str, len, start + 1, end + 1); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int count){ if (start+2>len-1) return count; else { if (str[start] == str[start + 2]) count++; return count_pairs(str, len, start + 1, count); } }
int count_pairs_wrapper(char *str, int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . if (len < 2 || str == NULL) return 0; else{ int c; c = count_pairs(str, len, 0, 2); return c; } }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ if (str[start] != str[start + 2]) { j = start + 1; return 0; } else { return 1 + count_pairs(str, len, start + 1, end); } }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end,int count){ int temp; if (end>=len) return 0; if (str[start] == str[end]) count++; temp = count_pairs(str, len, start + 1, end + 1, count); if (temp != 0) count = temp; return count; }
int is_onepair (hand_t hand) { int numPairs = 0; int pairs = count_pairs(hand); if (pairs >= 1) { numPairs = 1; return numPairs; } else return numPairs; }
int is_twopairs (hand_t hand) { int numPairs = 0; int pairs = count_pairs(hand); if (pairs == 2) { numPairs = 1; return numPairs; } else return numPairs; }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int len, int start, int end){ int count = 0; if (str[start] == str[end]) count = 1; else count = 0; start++; end = start + 2; if (str[end] != '\0') count = count + count_pairs(str,len,start,end); return count; }
int count_pairs_wrapper(char *str,int len){ //Wrapper function which might call a recursive function ,which might take extra parameters . int result = 0; //printf("\nstr-%s", str); if (len < 3){ return result; } else{ result = count_pairs(str, len, 0, 2); //printf("\nres-%d", result); return result; } }
int main() { int i,x; scanf("%d%d",&n,&d); for (i=0;i<n;i++) { scanf("%d",&x); ins(x); } count_pairs(); printf("%d",count); return 0; }
int count_pairs_wrapper(char *str,int len) { /*non-recursive approach if (str==NULL||len<=0) return 0; int i = 0, count = 0; for (i = 0; i < len - 2; i++) if (str[i] == str[i + 2]) count++; return count;*/ return count_pairs(str,len, 0, len-1); }
//You can use this function ,for the actual recursion .Think of similar functions for all other problems. int count_pairs(char *str, int start, int end, int count){ if (end == 0 || str == NULL) return 0; if (start + 2 == end) return count; if (str[start] == str[start + 2]) count++; if (start + 2 != end) { start++; temp = count_pairs(str, start, end, count); } return temp; }