CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;
int T(int n,int k){
if (n<k) return 0;
if(n==k) return k;
if(k<0) return 0;

if(n==1 && k==0) return 0;
if(n==2 && k==0) return 1;
if(n==2 && k==1) return 0;
if(n==3 && k==0) return 1;
//if(n==3 && k==1) return 2;

return T(n-1, k-1) + T(n-2, k) + T(n-3, k);
}
int main(){
    int n,k,num=0,a=0;
    cin>>n>>k;
    cout<<T(n,k);

    
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: A
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;

    int T(int n , int k){
        if (n==1 && k==0)
            return 0;
        
        if(n==1 && k==1) return 1;
        
            if(n==2 && k==0)
                return 1;
            
            if(n==2 && k==1)
                return 0;
            
            if(n==2 && k==2)
                return 1;
            
            if(n==3 && k==0)
                return 0;
            
            if(n==3 && k==1)
                return 2;
            
            if(n==3 && k==2)
                return 0;
            
            if(n==3 && k==3)
                return 1;
                
            
            if(k==0)
            return (T(n-2,k)+ T(n-3,k));
                 return ( T(n-1,k-1) + T(n-2,k) + T(n-3,k) );
            
            

            
        }

        int main(){
            int n,k;
            cin>>n>>k;
            cout<< T(n,k)<< endl;
        }

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: B
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include<iostream>
using namespace std;
int tB(int n, int k){
    if(k==n-1 || n<k) return 0;
    if(n<0 || k<0) return 0;
    return tB(n,k)=tB(n-1,k-1)+tB(n-2,k)+tB(n-3,k);
}
int main(){
    int n,k;
    cin>> n >> " " >> k;
    cout<< tB(n,k)<<endl;
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: C
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include <iostream>
using namespace std;

int doit(int n, int k){
    if(k<0){return 0;}
    else if(n<=0){return 0;}
    else if(n==2 && k==0){return 1;}
    else if(n==1 && k==0){return 0;}
    else if(n==1 && k==1){return 1;}
    else if(n==k){return 1;}
    else if(n<k){return 0;}
    else{
    return doit(n-1,k-1) + doit(n-2,k) + doit(n-3,k);
    }
}
int main(){
    int n,k;
    cin>> n>>k;
    cout<< doit(n,k);
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: A
Problem: ​
Assume you are given blocks of size 1, 2 and 3. Write a C++ program to recursively count the number of ways in which a tower of size n can be built with these blocks, such that exactly k of the blocks are of size 1.

 

Example: If n = 4 and k = 2, then there are three possible ways in which the tower can be built. If L1, L2, L3 represent the lego blocks of sizes 1, 2, 3 respectively, then the tower of size 4 can be built using the following block arrangements:

 

L1, L1, L2

L1, L2, L1

L2, L1, L1

 

HINT: If T(n, k) represents the number of ways in which a tower of size n can be built with exactly k 1-sized blocks, then T(n, k) can be recursively written as:

 

T(n,k) = T(n-1, k-1) + T(n-2, k) + T(n-3, k)

where

T(n-1, k-1) represents the number of ways in which a size 1 block is used first, i.e., the number of ways to build a tower of size (n-1) containing exactly (k-1) blocks of size 1.
T(n-2, k) represents the number of ways in which a size 2 block is used first, i.e., the number of ways to build a tower of size (n-2) containing exactly k blocks of size 1.
T(n-3, k) represents the number of ways in which a size 3 block is used first, i.e., the number of ways to build a tower of size (n-3) containing exactly k blocks of size 1.
Use this recurrence formula to implement the recursive function. Think carefully about the base cases.

 

Note: 

You need to solve this question using recursion only. 
Solutions using any other approach will not be considered and any testcases that pass will be negated i.e. will be given a 0. 
 

Input Format

A line containing two positive integers n and k, separated by a space
 

Output Format

An integer representing the count of valid ways to build a tower.
 

Assumptions on Input

Assume that the value of n entered by the user will be between 1 and 15, both inclusive
Assume that the value of k entered by the user will be between 1 and 10, both inclusive
If it is not possible to construct a tower, return 0.

Student submission:
#include <iostream>
using namespace std;

int tower(int n,int k){
    if(k>n || k<0)return 0;
    if(n==1){
        return k;
    }
    if(n==2){
        if(k==0)return 1;
        if(k==1)return 0;
        if(k==2)return 1;
    }
    if(n==3){
        if(k==0 || k==3)return 1;
        if(k==1)return 2;
        if(k==2)return 0;
    }
    return (tower(n-1,k-1)+tower(n-2,k)+tower(n-3,k));
}

int main(){
    int n,k;
    cin >> n >> k;
    cout << tower(n,k);
}

Grading criterion: Implementation of the Recursive Relationship
Rating A: Correctly implements the recursive call as defined in the hint. 

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
int string_compare(char *A,char *B){
	int i=0;
	while(true){
		if(A[i]==0 && B[i]==0){cout<<i+1;return 0;}
		if(A[i]==0){cout<<i+1;return -1;}
		if(B[i]==0){cout<<i+1;return +1;}
		if(A[i]>B[i]){cout<<i+1;return -1;}
		if(A[i]<B[i]){cout<<i+1;return +1;}
		i++;
	}
	cout<<i+1;return 0;
}
void swap(char &a,char&b){char temp=a;a=b;b=temp;return;}
void string_sort(char A[][12],int n){
	int sw=0;
		for(int k=0;k<n;k++){
			if(string_compare(A[k][12],A[k+1][12])==-1){
				sw=sw+1;swap(A[k][12],A[k+1][12]);
			}
		}
	char B[n][12];
	for(int m=0;m<n;m++){B[n-1-m][12]=A[m][12];}
	for(int h=0;h<n;h++){cout<<B[h][12]<<endl;}
	cout<<n<<endl<<sw;return;}
int main(){
	int n,m;cin>>n;char A[n][12];int i,j;
for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>A[i][j]; 
	string_sort(A[n][12],n);
}
	
}
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return -1;
if (second[i] == 0) return +1;
if (first[i] < second[i]) return -1;
if (first[i] > second[i]) return +1;
i++;
}
return 0;
}
void string_sort( char*string, int m){
int maxindex=0;
for (int i=1; i<m; i++){
if(string[maxindex]<string[i]) maxindex=i;
}
for(j=1; j<m; j--){
swap( string[maxindex], string[j-1]);
}
int main(){
int n;
cin>>n;
int A[n][MAX];
cin.getline(n,MAX);
}




























int main(){

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
int main()
{
int n,i;
int array[n];
cin>>array[n];
for(i=0;i<n;i++){
int string_sort(n);
cin>>n;
}
cout<<n;
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
Assigned grade: D
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
#define Max 11
using namespace std;
int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return -1;
if (second[i] == 0) return +1;
if (first[i] < second[i]) return -1;
if (first[i] > second[i]) return +1;
i++;
}
return 0;
}
int minindex(char s[][Max],int n){
 		for(int i=0;i<n;i++){
 			for(int j=0;j<Max;j++){
 				char a[n];
 				a[i]=s[i][j];
 			}
 		}
 				for(int k=0;k<n;k++){
 					int cnt=string_compare()
 				}
 			}
 		}
}
 		}
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
int string_compare(char *A,char *B){
int i=0;
while(true){
if(A[i]==0) && B[i]==0)return 0;
if(A[i]==0)return 1;
if(A[i]<B[i]) return 1;
if(A[i]>B[i]) return -1;
i++;
}
return 0;
}
int inputStrings(char **A,int n){
int numString=0;
for(int j=1;j<n;j++){
int k=string_compare(a[numString],a[j]);
if(k==1) numString=j;}
return numString;
}
void myswap(char *&A,char *&B){
char *temp=A;
A=B;
B=temp;
}
void string_sort(char *&A,int n){
for(int i=n;i>0;i--){
int numString=inputString(A,n);
myswap(a[numString],A[i-1]);
}}

int main(){
int n;
cin>>n;
char *A=new char [n];
for(int i=0;i<n;i++){
A[i]=new char[10]; }

for(int i=0;i<n;i++){
cin.getline(A[numString],10);
}
int res=string_compare(A,B);
cout<<res;
int d=inputstring(*A,n);
cout<<d;
string_sort(A,n);
return 0;
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
Assigned grade: B