CodeGraderBench/CodeGraderBench huggingface dataset:
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<simplecpp>
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++;
}
}

void stringreverse(char *s1, char* s2){
char s[100];
//for(int i=0;i<100;i++){
//s[i]="0";
//}
for(int i=0;i<100;i++){
s[i]=s1[i];s1[i]=s2[i];s2[i]=s[i];
}}
void stringsort(char A[][100],int n,int &l,int&m){
    int i, j;l=-1;m=0;
    for (i=1;i < n;i++){ 
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j])==-1) { 
	
            stringreverse (A[j-1],A[j]);m++;
            j = j - 1;
        }l++;
    }

}

main_program{
int n,l,m;

cin>>n;
char A[n][100];
//for(int i=0;i<n;i++){
//(int j=0;j<n;j++){A[i][j]="0";}
//}
for(int i=0;i<n;i++){cin>>A[i];}
stringsort(A,n,l,m);
for(int i=0;i<n;i++){cout<<A[i]<<endl;}
cout<<m<<endl;
cout<<l<<endl;



}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: B
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>
using namespace std;
int string_compare(char* p,char* q)
{
int pi=0;
while(p[pi]!=0 && q[pi]!=0)
	{
	  if(p[pi]>q[pi]){return -1;}
	  if(p[pi]<q[pi]){return 1;}
	  pi++;  }
	  if(p[pi]==0 && q[pi]==0){return 0;}
	  if(p[pi]==0){return 1;}
	  if(q[pi]==0){return -1;}  }


int string_swap(char** A,int n,int& p)
	{int swapi=0;
	  for(int i=1;i<n;i++)
		{
		  for(int j=i-1;j>=0;j--){p++; if(string_compare(A[j],A[j+1])==-1)
						{char* temp=A[j];swapi++;
						 A[j]=A[j+1]; A[j+1]=temp;}
					   else{break;}}}
		return swapi; }
int main(){
int n;
cin>>n;
char** A;
A= new char*[n];
for(int i=0;i<n;i++){A[i]=new char[12]; cin>>A[i];}
int p=0;
int swapi=string_swap(A,n,p);
for(int i=0;i<n;i++){cout<<A[n-i-1]<<endl;}
cout<<p<<endl<<swapi;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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>
using namespace std;
int compareCount=0;int swapCount=0;
int string_compare (char *first, char * second){
	int i = 0;compareCount++;
	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 a[15][12],int n){
	for (int i=1;i<n;i++){
		char obj[12]=a[i];int j=i-1;
		while(string_compare(obj,a[j])==+1 && j>=0){
			a[j+1]=a[j];j--;swapCount++;
		}a[j+1]=obj;
	}
}
*/	
int main(){
	int n;cin>>n;char a[15][12];
	for (int i=0;i<n;i++){
		cin>>a[i];
	}//string_sort(a,n);
	for (int i=n-1;i>=0;i--){
		cout<<a[i][0]<<endl;
	}cout<<compareCount<<endl<<swapCount;
	return 0;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: C
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>
using namespace std;
int cmp=0;
int sw=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(second[i]<first[i]) return 1;
      i++;
     }
     return 0;}

void string_sort(char x[100][100],int n){
        int i,j;
        char c[100];
        for (i=1;i<n;i++){
        j=i;
        int p=string_compare(x[j-1],x[j]); cmp++;
        while(j>0&& string_compare(x[j-1],x[j])==-1){ 
               sw++;
               strcpy(c,x[j]);
               strcpy(x[j],x[j-1]);
               strcpy(x[j-1],c);
          j--;
        }
    }
}

int main(){
        char x[100][100];
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
          cin>>x[i];
        }
        string_sort(x,n);
        for(int i=0;i<n;i++){
         cout<<x[i]<<endl;}
        cout<<cmp+1<<endl<<sw;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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>
using namespace std;
#define MAX 100
int string_compare (char *first, char * second){
//a++;
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 swap(char A[][MAX],int n1, int n2){
	for(int i=0;i<11;i++){
		char temp=A[n1][i];
		A[n1][i]=A[n2][i];
		A[n2][i]=temp;
	}
}
void insertion_sort (char A[][MAX], int n) {
    int i, j;
    for (i=1;i < n;i++){ // for each element of the array
        j = i;
        while (j > 0 && A[j-1][0] < A[j][0]) { // find the location to insert it to
	 // maintain a sorted subarray of i elements
            swap (A,j,j-1);
            j = j - 1;
        }
    }
}
void print2Darray (char A[][MAX], int n){
int i,j;
for(i=0;i<n;i++){
		for(j=0;j<11;j++){
			cout << A[i][j];
		}
		cout << endl;
}
}
int main(){
int i,j,n; cin>>n;
char A[MAX][MAX];
for(i=0;i<n;i++){
	char x[100]; cin.getline(x,11);
		for(j=0;j<11;j++){
			if(x[j]==0) break;
			A[i][j]=x[j];
		}
}
print2Darray(A,n);
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: B
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>
using namespace std;
int a=0,b=0;
int string_compare (char *first, char * second){
int i = 0;
while (true){a++;
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++;
}

}
void string_copy (char *dest, const char* source) {
	int i;
	for(i=0;source[i]!= 0;i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}


void string_sort(char array[][12],int n){
int i,j;
for(i=1;i<n;i++){
j=i;
while(j>0 && string_compare(array[j-1],array[j])==1){
char m[12],n[12];
string_copy(m,array[j-1]);string_copy(n,array[j]);
string_copy(array[j-1],n);string_copy(array[j],m);
j=j-1;b++;


}
}
}

int main(){
int n;cin>>n;
char array[n][12];
for(int i=0;i<n;i++){cin>>array[i];}
string_sort(array,n);
for(int i=0;i<n;i++){
cout<<array[i]<<endl;
}

cout<<a<<endl;
cout<<b<<endl;


}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: B
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>
using namespace std;
int main()
{int n;
cin>>n;
char name[n-1][20];
int count=0;
while (cin.getline(name[count++], 20));
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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<cstring>
#include<cmath>
#include<iostream>
using namespace std;

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

}
return 0;
}

//void swapc(char a[],char b[])
//{
//char temp[100];
//for(int i=0;i<15;i++)
//{
//temp[i]=a[i];
//a[i]=b[i];
//b[i]=temp[i];
//}
//}




int string_sort(char a[][12],int n)
{
int m=0,c=0;
	
	
	int i,j;
	for (i=1;i < n;i++){ 
        j = i;
        int b=string_compare(a[j-1],a[j]);
        if(b!=20){c++;}
        while (j > 0 && b==1) { 
	             swap (a[j],a[j-1]);
            j = j - 1;
        }
    }

	
	
	
	
	return c;
	
}


int main()
{
int n;cin>>n;
char A[n][12];
for(int i=0;i<n;i++){
cin>>A[i];
}
int c=string_sort(A,n);
	for(int i=0;i<n;i++){
	cout<<A[i]<<endl;
}
cout<<endl<<c;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: C
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>
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 main()
{
int n;
cin>>n;
char A[n];
char B[n];
cin>>A;
cin>>B;
cout<<string_compare(A,B);


}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: D