diff --git a/c/food_line.c b/c/food_line.c new file mode 100644 index 0000000..e18dc4b --- /dev/null +++ b/c/food_line.c @@ -0,0 +1,36 @@ +// this is a small program solution for food line programing challenge + +#include +#include +#include + +#define MAX_LINES 100 + +//finds shortest line for new people +int shortest_line_index(int lines[], int n) { + int j, shortest = 0; + for (j = 1;j < n; j++) + if (lines[j] < lines[shortest]) + shortest = j; + return shortest; +} + +void solve(int lines[], int n, int m) { + int i, shortest; + for (i = 0;i < m; i++) { + shortest = shortest_line_index(lines, n); + printf("in line %d : no of people %d\n", shortest + 1, lines[shortest]); + lines[shortest]++; + } +} + +int main(void) { + int lines[MAX_LINES]; + int n, m, i; + printf("enter number of \"lines\" \"new people\" : "); + scanf("%d%d", &n, &m); + for (i = 0;i < n; i++) + scanf("%d", &lines[i]); + solve(lines, n, m); + return 0; +} diff --git a/c/snowflake.c b/c/snowflake.c new file mode 100644 index 0000000..ee3613d --- /dev/null +++ b/c/snowflake.c @@ -0,0 +1,86 @@ +//this program i for to find identical pair of snowflak in given input max of 100000 + + +#include +#include +#include +#define MAXSIZE 100000 + +//this function check tow flaks are identical from the starting position to the right +int identical_right (int flak1[], int flak2[], int start) +{ + int offset; + for (offset = 0; offset < 6; offset++) + { + if (flak1[offset] != flak2[(start + offset) % 6]) + return 0; + } + return 1; +} + +//checks flaks are identical from start to left +int identical_left (int flak1[], int flak2[], int start) +{ + int offset; + for (offset = 0; offset < 6; offset++) + { + if ((start - offset) < 0) + if (flak1[offset] != flak2[(start - offset) + 6]) + return 0; + if (flak1[offset] != flak2[(start - offset) + 6]) + return 0; + + } + return 1; +} + +//returns true if flaks identical in start to left or right else false +int isIdentical (int flak1[], int flak2[]) +{ + int start; + for (start = 0; start < 6; start++) + { + if (identical_right(flak1, flak2, start)) + return 1; + if (identical_left(flak1, flak2, start)) + return 1; + } + return 0; +} + +//taks array of snowflakes and checks for identiacl +int identify_identical(int snowflaks[][6], int n) +{ + int i, j; + for ( i=0; i