CodeGraderBench/CodeGraderBench huggingface dataset:
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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 500
using namespace std;
void swap(char *x,char *y)
	{char temp[MAX][11];
	temp[0]=*x;
		*x=*y;
		*y=temp[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 bubblesort(char parent[][MAX],int n)
 	{    for(int j=0;j<n-1;j++)
 		{
 		for(int i=n;i>0;i--)
 	{	
 	if(string_compare(parent[i-1],parent[i])==1)
 		{swap(parent[i],parent[i+1]);
 		}
 			else continue;
 			}
 		
 		}
 	}
int main()
{int n;cin>>n;
char name[MAX][MAX];
int count=0;
for(int i=0;i<n;i++)
{cin>>name[i];
}
bubblesort(name,n);
for(int j=0;j<n;j++)
cout<<name[j]<<endl;
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
Rating D: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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<simplecpp>
 #define MAX 11
 
 int str_l(char *x)
{
	int L = 0;
	while (x[L] != '\0') L++;
return L;
}

 
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 swap(char *a,char *b){
char *temp;
string_copy (temp,a);
string_copy (a,b);
string_copy(b,temp);}
	
 
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 inp[][MAX],int n){

{
    int i, j;
    for (i = 0; i < n - 1; i++)
    {
        // Last i elements will be in place after this for loop
        for (j = 0; j < n - i - 1; j++)
        {
            if(string_compare(inp[j],inp[j+1])==-1){
            swap(inp[j],inp[j+1]);}}}}}

 
main_program{
int n;
cin>>n;

char name[n][MAX];
int count=0;

while (cin.getline(name[count++], 11));


string_sort(name,n);
for (int i=0; i<count; i++)
cout  << " " << name[i] << " " << endl;}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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 one[], char two[]){
	int i=0;
	while (true){
		
		if ((one[i]==0)&& (two[i]==0)) return(0);
		if (one[i]==0) return(1);
		if (two[i]==0) return(-1);

		if (one[i]>two[i]) return(-1);
		if (one[i]< two[i]) return(1);
		
		i++;

	}
}

int string_sort(char str1[][12] ,int n){
	int i,j, swaps=0;
	for ( i=0; i<n-1; i++){
		for(j=0; j<n-i-1;j++){
			int r=string_compare(str1[j], str1[j+1]);
			if (r==1)
			
				/*{char temp[12]=str1[j];
				str1[j]=str1[j+1];
				str1[j+1]=temp;*/
				{swap(str1[j], str1[j+1]);}
				swaps++;
				}

		}
		return swaps;

	}


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

	for ()
	

}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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>
#include<cmath>
using namespace std;
int main()
{
int n,s;
cin>>n;
s=2pow(n);
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
Rating D: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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>
#include <cstring>
using namespace std;

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

int string_compare (char *A, char *B)
{
	int i=0;
	
	while (A[i] != 0 && B[i] != 0)
	{
		if (A[i] < B[i]) return 1;
		if (A[i] > B[i]) return -1;
		
		i++;
	}
	
	if (A[i] == 0 && B[i] == 0) return 0;
	if (A[i] == 0) return 1;
	if (B[i] == 0) return -1;
	
	else return 0;
}

void string_sort (char A[][12], int n, int& a, int& b)
{
	char temp[12];

	for (int i=0; i<n-1; i++)
	{
		for (int j=n-2; j>=i; j--)
		{
			a++;
			if (string_compare (A[j], A[j+1]) == 1)
			{
				strcopy (temp, A[j]);
				strcopy (A[j], A[j+1]);
				strcopy (A[j+1], temp);
				b++;
			}
		}
	}
}	


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

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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_reverse_in_place (char* s){
	int n = string_length(s);
	for(int i=0;i<n/2;i++) swap(&s[i],&s[n-1-i]);
	s[n] = 0;
}

int main(){
	int m,n;
	cin >> m >> n;
	char first[m],second[n];
	for (int i=0;i<m;i++){
		cin >> first[i];
	}
	for (int i=0;i<n;i++){
		cin >> second[i];
	}



}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
Rating D: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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<simplecpp>

int string_length (char*n)
{
int s = 0 ;
while (n[s] ! = '\0') s++ ;
return s;
}
 void bubble_sort(float*s, int n)
{
int i, j ; 
for (i=0;i<n-1;i++)
      {
for ( j=0; j<n-i-1; j++)
              {
if (s[j] > s[j+1])
swap(&s[j], &s[j+1]);
              }
      }
}
main_program
{
   float s[100];
int i,n;
cout << endl << " enter the number of numbers " ; cin >> n;
for (i=0; i<n; i++)
{
   cout<<endl<< "enter the next number"  ;
 cin>>s[i];
}
cout<<endl<<"the unsorted array is"<<endl;
for (i=0; i<n; i++)
{
   cout << s[i] << " " ;
}
bubble_sort(s,n);
cout << endl << "the sorted array is" << endl;
for (i=0; i < n; i++)
 {
   cout << s[i] << " ";
 }

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
Rating D: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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;
#define MAX 12
void swap(char a[], char b[]){
    char temp[MAX];
    for(int i =0; i<11;i++){
        temp[i]=a[i];
    }
    for(int i =0; i<11;i++){
        a[i]=b[i];
    }    
    for(int i =0; i<11;i++){
        b[i]=temp[i];
    }

}
int string_compare(char a[], char b[]){
    for(int i=0; i<11;i ++){
        if(int(a[i])>int(b[i])){
            return -1;
            break;
        }else if(int(b[i])>int(a[i])){
            return 1;
            break;
        }
        continue;
    }
    return 0;
}
void bsort(char a[][MAX], int n, int &cmp, int &swp)
{
    for (int i = 0; i < n ; i++){
        for (int j = 0; j < n - i - 1; j++){
            cmp++;
            if(string_compare(a[j], a[j+1])==1){
                swap(a[j],a[j+1]);
                swp++;
            }else if(string_compare(a[j], a[j+1])==-1){
                continue;
            }
        }
    }
}

int main(){
    int n;
    cin>>n;
    int cmp,swp;
    cmp=swp=0;
    char a[n][MAX];
    for(int i=0;i<n;i++){
        cin.getline(a[i],11); //cout<<i<<endl<<endl;
    }
    bsort(a,n,cmp,swp);
    for(int i=0;i<n;i++){
        cout<<a[i]<<endl;
    }
    cout<<cmp<<" "<<swp;
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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 isIncreasingDecreasing (int *A, int n){
int val=0;
for(int i=0;i<n-1;i++){
if(A[i]<A[i+1]){
val+=1;
}
else if(A[i]>A[i+1]){
val+=-2;}
}
if(val==n-1){return 1;}
else if(val==-2*(n-1)){return 2;}
else return 3;
}
int main(){
int n;
cin>>n;
int A[n];
for(int i=0;i<n;i++){
cin>>A[i];
}
if(1 <= n&& n < 25){cout<< isIncreasingDecreasing (A,n);}
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
Rating D: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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;
#define max 12
int comp;
int swapcount;
int string_compare(char *str1,char *str2)
{
int l=0;
while(str1[l]!=0&&str2[l]!=0)
{
if(str1[l]<str2[l])
return 1;
if(str1[l]>str2[l])
return -1;
l++;
}
if(str1[l]!=0)
return -1;
if(str2[l]!=0)
return 1;
return 0;
}
void string_sort(char str[][max],int n)
{
comp=0;
swapcount=0;
for(int i=0;i<n;i++)
{
bool flag=false;
for(int j=0;j<n-i-1;j++)
{
comp++;
if(string_compare(str[j],str[j+1])==1)
{
swap(str[j],str[j+1]);
swapcount++;
flag=true;
}
}
if(flag==false)
break;
}
}
void swap(char *str1,char *str2)
{
for(int l=0;l<max;l++)
{
char ch=str1[l];
str1[l]=str2[l];
str2[l]=ch;
}
}
int main()
{
int n;
cin>>n;
char str[n][max];
for(int i=0;i<n;i++)
cin>>str[i];
string_sort(str,n);
for(int i=0;i<n;i++)
cout<<str[i]<<" ";
cout<<endl;
cout<<comp<<" "<<swapcount;
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
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 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-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<simplecpp>
int string_compare (char a[][11], int n)
{
     
          int j = 0;
	  while (true)
	  {
		if (a[n][j] == 0 && a[n+1][j] == 0) return 0;
		if (a[n][j] == 0) return 1;
		if (a[n+1][j] == 0) return -1;
		if (a[n][j] < a[n+1][j]) return +1;
		if (a[n][j] > a[n+1][j]) return -1;
		j++;
	  }
} 
void string_sort( char a[][11], int n)
{
    int c;
    char temp[11];
    for(int i=0;i<n;i++)
    {
        int k=0,j=0;//,m=0,n=0,p=0,l=0;
       c=string_compare(a,i);
       if(c==1) 
       {
       for(k=0,j=0;;k++,j++) temp[k++]=a[i][j++];
        for(k=0,j=0;;k++,j++) a[i][k++]=a[i+1][j++];
         for(k=0,j=0;;k++,j++) a[i+1][k++]=temp[j++];
        
       }
    }
    for(int i=0;i<n;i++)
    {
      
         cout<<a[i]<<endl;
      
      
    }
} 


main_program
{
   int n,i,c;
   cin>>n;
   char a[n][11];
  for(i=0;i<n;i++)
   {
     cin.getline(a[i],11);
   }
   
  /*for(i=0;i<n;i++) 
   {
    c=string_compare(a,n);
    cout<<c;
    }*/
    string_sort(a,n);
   
   
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function
Rating C: 0
Rating D: 0
Assigned grade: A