CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: You are given a sequence of integers. Your task is to reverse the sequence, print it, and then replace all odd numbers in the original sequence with 0 and print the modified sequence.



Your Task

1. Read an integer N representing the number of elements.
2. Read N integers into an array/vector.
3. Print the elements in reverse order.
4. Traverse the original array and replace every odd number with 0.
5. Print the updated array after replacement.



Input Format

- An integer N.
- N integers representing the elements.



Output Format

- First line: Print the array in reverse order with spaces.
- Second line: Print the modified array where all odd numbers are replaced by 0.

Assumptions on Input

- 1 <= N <= 10^5
- Elements are integers.

Student submission:
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    for(int i=0;i<n;i++){
        cout<<A[n-i-1]<<" ";
    }
    cout<<endl;
    for(int i=0;i<n;i++){
        if(A[i]%2!=0){
            A[i]=0;
        }
        cout<<A[i]<<" ";
    }
}

Grading criterion: Output
Rating A: Correctly prints the output

Rating B: Some issue
Rating C: Major issue
Rating D: 0
Assigned grade: A
Problem: You are given a sequence of integers. Your task is to reverse the sequence, print it, and then replace all odd numbers in the original sequence with 0 and print the modified sequence.



Your Task

1. Read an integer N representing the number of elements.
2. Read N integers into an array/vector.
3. Print the elements in reverse order.
4. Traverse the original array and replace every odd number with 0.
5. Print the updated array after replacement.



Input Format

- An integer N.
- N integers representing the elements.



Output Format

- First line: Print the array in reverse order with spaces.
- Second line: Print the modified array where all odd numbers are replaced by 0.

Assumptions on Input

- 1 <= N <= 10^5
- Elements are integers.

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

int main(){
    int n ; 
    cin>>n ;
    int A[100] ;
    for(int i = 0 ; i < n ; i++){
        cin>>A[i];
    };
    for(int i=n-1 ; i>= 0 ; i--){
        cout<<A[i]<<" ";
    };
    cout<<endl;
    for (int i = 0 ; i<n ; i++){
        if(A[i]%2==0){cout<<A[i]<<" ";}
        else {cout<<0<<" " ;}
    }

}

Grading criterion: Output
Rating A: Correctly prints the output

Rating B: Some issue
Rating C: Major issue
Rating D: 0
Assigned grade: A
Problem: You are given a sequence of integers. Your task is to reverse the sequence, print it, and then replace all odd numbers in the original sequence with 0 and print the modified sequence.



Your Task

1. Read an integer N representing the number of elements.
2. Read N integers into an array/vector.
3. Print the elements in reverse order.
4. Traverse the original array and replace every odd number with 0.
5. Print the updated array after replacement.



Input Format

- An integer N.
- N integers representing the elements.



Output Format

- First line: Print the array in reverse order with spaces.
- Second line: Print the modified array where all odd numbers are replaced by 0.

Assumptions on Input

- 1 <= N <= 10^5
- Elements are integers.

Student submission:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main(){
    int a;
    int b[100];
    cin>>a;
    for (int i=0;i<a;i++){
        cin>>b[i];
    }
    for (int i=a-1;i>=0;i--){
        cout<<b[i]<<" ";
    }
    cout<<endl;
    for (int i=0;i<a;++i){
        if (b[i]%2!=0){
            b[i]=0;
        }
    }
    for (int i=0;i<a;i++){
        cout<<b[i]<<" ";
    }
}

Grading criterion: Output
Rating A: Correctly prints the output

Rating B: Some issue
Rating C: Major issue
Rating D: 0
Assigned grade: A
Problem: You are given a sequence of integers. Your task is to reverse the sequence, print it, and then replace all odd numbers in the original sequence with 0 and print the modified sequence.



Your Task

1. Read an integer N representing the number of elements.
2. Read N integers into an array/vector.
3. Print the elements in reverse order.
4. Traverse the original array and replace every odd number with 0.
5. Print the updated array after replacement.



Input Format

- An integer N.
- N integers representing the elements.



Output Format

- First line: Print the array in reverse order with spaces.
- Second line: Print the modified array where all odd numbers are replaced by 0.

Assumptions on Input

- 1 <= N <= 10^5
- Elements are integers.

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0; i<n; i++) cin >> vec[i];

    for(int i=n-1; i>=0; i--) cout << vec[i] << " ";
    cout << endl;

    for(int i : vec) {
        if(i%2) cout << 0 << " ";
        else cout << i << " ";
    }
    return 0;
}

Grading criterion: Output
Rating A: Correctly prints the output

Rating B: Some issue
Rating C: Major issue
Rating D: 0
Assigned grade: A
Problem: You are given a sequence of integers. Your task is to reverse the sequence, print it, and then replace all odd numbers in the original sequence with 0 and print the modified sequence.



Your Task

1. Read an integer N representing the number of elements.
2. Read N integers into an array/vector.
3. Print the elements in reverse order.
4. Traverse the original array and replace every odd number with 0.
5. Print the updated array after replacement.



Input Format

- An integer N.
- N integers representing the elements.



Output Format

- First line: Print the array in reverse order with spaces.
- Second line: Print the modified array where all odd numbers are replaced by 0.

Assumptions on Input

- 1 <= N <= 10^5
- Elements are integers.

Student submission:
#include<iostream>
using namespace std;
int main(){

    int n; cin>>n;
    int A[n];
    for(int i=0;i<n;i++) cin>>A[i];

    for(int j=n-1;j>=0;j--) cout<<A[j]<<' ';

    for(int k=0;k<n;k++){

        if(A[k]%2==1) A[k] = 0;
    }
cout<<endl;
    for(int l=0;l<n;l++) cout<<A[l]<<' ';
}

Grading criterion: Output
Rating A: Correctly prints the output

Rating B: Some issue
Rating C: Major issue
Rating D: 0
Assigned grade: A
Problem: You are given a sequence of integers. Your task is to reverse the sequence, print it, and then replace all odd numbers in the original sequence with 0 and print the modified sequence.



Your Task

1. Read an integer N representing the number of elements.
2. Read N integers into an array/vector.
3. Print the elements in reverse order.
4. Traverse the original array and replace every odd number with 0.
5. Print the updated array after replacement.



Input Format

- An integer N.
- N integers representing the elements.



Output Format

- First line: Print the array in reverse order with spaces.
- Second line: Print the modified array where all odd numbers are replaced by 0.

Assumptions on Input

- 1 <= N <= 10^5
- Elements are integers.

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

int main(){
    int n;
    cin>>n;
    vector<int> vec;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        vec.push_back(a);
    }
    for(int i=n-1;i>=0;i--){
        cout<<vec[i]<<" ";
    }
    cout<<endl;
     
    for(int i=0;i<n;i++){
        if(vec[i]%2==1){
            vec[i]=0;
        }
    }

    for (int i=0;i<n;i++){
        cout<<vec[i]<<" ";
    }

    return 0;
}

Grading criterion: Output
Rating A: Correctly prints the output

Rating B: Some issue
Rating C: Major issue
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#define max 100
using namespace std;
int count=0;
void swap(char*&a,char*&b){

char t[max];
int i=0;

while(a[i]!='\0'){
t[i]=a[i];i++;}
t[i]='\0';

i=0;

while(b[i]!='\0'){
a[i]=b[i];i++;}
a[i]='\0';

i=0;

while(t[i]!='\0'){
b[i]=t[i];i++;}
b[i]='\0';

}




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 insertion_sort (char a[][max], int n) {
    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        int num=string_compare(a[j],a[j-1]);
        while (j > 0 && (num==-1)) {
            count++; 
            swap (a[j],a[j-1]);
            j = j - 1;
        }
    }
}

int main(){
int n;
cin>>n;
char arr[n][max];
for(int i=0;i<n;i++){
cin>>arr[i];
}
insertion_sort(arr,n);
for(int i=n;i>0;i--){
cout<<arr[i]<<endl;}
cout<<count;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#define MAX 100
using namespace std;
int p=0;
int q=0;

int string_compare(char A[][MAX],int i,int j){
q=q+1;
while(true){
int k=0;
if (A[i][k]==0 && A[j][k]==0) return 0;
if (A[i][k]==0) return -1;
if (A[j][k]==0) return 1;
if (A[i][k]<A[j][k]) return -1;
if (A[i][k]>A[j][k]) return 1;
k=k+1;
}
return 0;
}
char swap (char A[][MAX],int i,int j){
char temp[MAX];
int k=0;
while(A[i][k]!='/0'){
temp[k]=A[i][k];
k=k+1;
}
temp[k]='/0';
k=0;
while(A[j][k]!='/0'){
A[i][k]=A[j][k];
k=k+1;
}
A[i][k]='/0';
k=0;
while(temp[k]!='/0'){
A[j][k]=temp[k];
k=k+1;
}
A[j][k]='/0';
p=p+1;
}
void string_sort(char A[][MAX],int n){
for(int i=1;i<n;i++){
int j=i;
while(j>0 && string_compare(A,j-1,j)==-1){
swap (A,j-1,j);
}
}
}
int main(){
char A[MAX][MAX];
int n;
cin>>n;
for(int i=0;i<n;i++){
cin.getline(A[i],12);
string_sort(A,n);
for(int i=0;i<n;i++){
int k=0;
while(A[i][k]!='/0'){
cout<<A[i][k];
k=k+1;
}
cout<<endl;
}
cout<<p<<endl<<q;
}
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#include<cstring>
#include<cmath>
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 swapt(char *a, char *b){
char tempt[100];
for(int i=0; i<15; i++)
{
tempt[i]=a[i];
a[i]=b[i];
b[i]=tempt[i];
}}

void string_sort (char A[][12], int n) {
    int i, j,c;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && A[j-1] < A[j]){
            swapt(&A[j],&A[j-1]);c++;
            j = j - 1;
        }
    }
}

int main(){
int n;
cin>>n;
//char a[n][12];
//for(int i=0;i<n;i++)
//{
//cin>>a[i];
//}
//char b[n][12]=string_sort(a,n);
//cout<<b[n][12];
//}
char name[n][12];
int count=0;
cout << "Enter at most 5 names with at most 19 characters each:\n";
while (cin.getline(name[count++], 20)); // terminated by ctrl-Z
cout << "The names are:\n";
for (int i=0; i<count; i++)
cout << "\t" << i << ". [" << name[i] << "]" << endl;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

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

void swap(char*&a,char*&b){
	char t[max];
	int i=0;
	while(a[i]!='\0'){
		t[i]=a[i];i++;}
	t[i]='\0';
	i=0;
	while(b[i]!='0'){
		a[i]=b[i];i++;}
	a[i]='\0';
	i=0;
	while(t[i]!='\0'){
		b[i]=t[i];i++;}
	b[i]='\0';
	}

int string_compare(char *a,char*b){
	int i=0;
	while(true){
		if(a[i]=='\0' && b[i]=='\0') return 0;
		else if(a[i]=='\0') return -1;
		else if(b[i]=='\0') return 1;
		else if(a[i]>b[i]) return 1;
		else if(a[i]<b[i]) return -1;
		i++;}
	}

int string_sort(char a[][max],int n,int *noc){
	int count=0;
	for(int i=0;i<n;i++){
		bool flag=false;
		if(i==0) continue;
		else{
			int j=i;
			int gf=string_compare(a[j],a[j-1]);*noc+=1;
			while(string_compare(a[j],a[j-1])==1){
				swap(a[j],a[j-1]);count++;
				j--;flag=true;
				*noc+=1;
				if(j==0)break;}}
		if (flag==false)break;}
	return count;}

int main(){
	int n,noc=0;
	cin>>n;
	char words[n][max];
	for(int i=0;i<n;i++){
		cin>>words[i];}
	int h=string_sort(words,n,&noc);
	for(int i=0;i<n;i++){
		cout<<words[i]<<'\n';}
	cout<<noc<<"\n"<<h;}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#define MAX 50
using namespace std;
void string_swap(char A[], char B[]){
	char temp[MAX];
	int i, j, k;
	for(i=0; A[i]!=0; i++)
	{
		temp[i]=A[i];
	}
	temp[i]=0;
	for(j=0; B[j]!=0; j++)
	{
		A[j]=B[j];
	}
	A[j]=0;
	for(k=0; temp[k]!=0; k++)
	{
		B[k]=temp[k];
	}
	B[k]=0;
}
int string_compare(char A[], char B[]){
	int i=0;
	while(true)
	{
		if(A[i]==0 && B[i]==0){return 0;}
		else if(A[i]==0) {return 1;}
		else if(B[i]==0){return -1;}
		else if(A[i]>B[i]){return -1;}
		else if(B[i]>A[i]){return 1;}
		i++;
	}
}
void string_sort(char A[MAX][MAX], int n, int &a, int &b){
	int i,j;
	int cnt_cmp, cnt_swap;
	cnt_cmp=cnt_swap=0;
	for(i=1; i<n; i++)
	{
		j=i;
		cnt_cmp++;
		while(j>0 && (string_compare(A[j],A[j-1])==1))
		{
			string_swap(A[j],A[j-1]);
			j--;
			cnt_swap++;
			if(j!=0){cnt_cmp++;}
		}
	}
	a=cnt_cmp;
	b=cnt_swap;
}
int main(){
	int n, cnt_cmp, cnt_swap;
	cin >> n;
	char A[MAX][MAX];
	for(int i=0; i<n; i++)
	{
		cin>>A[i];
	}
	string_sort(A,n,cnt_cmp,cnt_swap);
	for(int j=n-1; j>=0; j--)
	{
		cout << A[j] << endl;
	}
	cout << cnt_cmp << endl;
	cout << cnt_swap;
	return 0;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: A