Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Arrays/1D Array/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<stdio.h>
void main()
{
int N,i,A[100];
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%d",&A[i]);
while((--N)+1)
printf("%d\n",A[N]);
}
20 changes: 20 additions & 0 deletions Arrays/Multi-D Array/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
void main()
{
int j,i,m,n,A[10][10],B[10][10];
scanf("%d %d",&m,&n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&A[i][j]);

for(i=0;i<m;i++)
for(j=0;j<n;j++)
B[j][i]=A[i][j];


for(i=0;i<n;i++)
{ for(j=1,printf("%d",B[i][0]);j<m;j++)
printf(" %d",B[i][j]);
printf("\n");
}
}
28 changes: 28 additions & 0 deletions Hash Tables/Hash Tables/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<stdio.h>
#include<stdlib.h>
struct Student
{
int roll;
char name[25]
};
void main()
{
int q,i,r,N,N1,j;
char nam[25];
scanf("%d",&N);
struct Student *ptr = (struct Student*) malloc (N * sizeof(struct Student));
for(i=0;i<N;i++)
scanf("%d %s",&(ptr+i)->roll,&(ptr+i)->name);
scanf("%d",&q);
for(i=0;i<q;i++)
{
scanf("%d",&N1);
for(j=0;j<N;j++)
{
if ((ptr+j)->roll==N1)
{ printf("%s\n",(ptr+j)->name);
break;
}
}
}
}
25 changes: 25 additions & 0 deletions Stacks/Stacks/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<stdio.h>

void main()
{
int f,i,N,cus[100000],top=-1;
scanf("%d",&N);
for(i=0;i<N;i++)
{
scanf("%d",&f);
if(f==1)
{
if(top<0)
printf("No food\n");
else
{
printf("%d\n",cus[top]);
top--;
}
}
else
{
scanf("%d",&cus[++top]);
}
}
}
66 changes: 66 additions & 0 deletions checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh
# Copyright 2018, Training Cell MEC

CC=cc
VERSION="0.1"

PROJ_PATH=$(pwd)
SOL_FILE="solution.c"
TESTCASE_DIR="tests"
OUTPUT_DIR=output

HELP_TEXT="Usage: $0 [-c CC ] [-d PATH] [-h] PROBLEM"

PROBLEM=

help() {
echo "$HELP_TEXT"
exit 0
}

error_exit() {
echo "critical error: $1"
exit 1
}

while [ $# != 0 ]; do
case $1 in
-h) help ;;
-c) CC=$2 ; shift ;;
-d) PROJ_PATH=$2 ; shift ;;
-*) ;;
*) PROBLEM=$1 ;;
esac
shift
done

[ -z "$PROBLEM" ] && error_exit "no problem specified"

# scratch directory
if [ ! -d "${PROJ_PATH}/${OUTPUT_DIR}" ]; then
mkdir "${PROJ_PATH}/${OUTPUT_DIR}" ||
error_exit "directory creation failed"
fi
find "${PROJ_PATH}/${OUTPUT_DIR}/" -maxdepth 1 -type f -delete ||
error_exit "directory operation failed"

# build the source
$CC -o "${PROJ_PATH}/${OUTPUT_DIR}/bin" "${PROJ_PATH}/${PROBLEM}/${SOL_FILE}" ||
error_exit "compilation failed"

# verify the output
for cs in $(find "${PROJ_PATH}/${PROBLEM}/${TESTCASE_DIR}/"\
-maxdepth 1 -iname 'in*.txt' -type f -exec basename "{}" \;); do
op_n=$(echo $cs | sed 's/in\(.\)\.txt/\1/') # n as in nth test case

"${PROJ_PATH}/${OUTPUT_DIR}/bin" <"${PROJ_PATH}/${PROBLEM}/${TESTCASE_DIR}/in${op_n}.txt"\
>"${PROJ_PATH}/${OUTPUT_DIR}/op${op_n}.txt"

cat "${PROJ_PATH}/${OUTPUT_DIR}/op${op_n}.txt" | shasum | cut -d ' ' -f 1 |
cmp -s -n 40 "${PROJ_PATH}/${PROBLEM}/${TESTCASE_DIR}/op${op_n}_hashed.txt" - &&
echo "test case ${op_n} passed" || echo "test case ${op_n} failed"
done

# cleanup
rm -r "${PROJ_PATH}/${OUTPUT_DIR}/" ||
error_exit "directory operation failed"