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>
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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
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;

void string_compare(char*a,char*b ) 
{ 
 for( int i=0;i<12;i++)
    {
        if(*a[i] > *b[i] )
        { cout<<1;}
        if ( *a[i]> *b[i] )
        { cout << -1;}
         else  ( *a[i]= *b[i] ) 
        { continue ; } ;
    } ;
}

void swap (char*a, char*b)
{
    char t;
    t= *a;
    *b = t;
}

void string_sort(char*A,char n)
{
    int i, j;
    for (i = 0; i < n - 1; i++)
    {
    
     for (j = 0; j < n - i - 1; j++)
        {
            if (A[j] > A[j + 1])
                swap(&A[j], &A[j + 1]);
        }
    }




int main()
{
char a[11] ; char b[11] 
    cin >> n;


cin >> a;
cin >> b; 
 
 string_compare(a,b );
string_sort(a,11);

}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
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;

void display (char A[]){
int i=0;
while (A[i]!="/0"){
cout << A[i];
}
cout<<" ";
}

void swap(char &a, char&b){
char temp;
temp=a;a=b;b=temp;
}

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 (b[i] == 0) return +1;
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return +1;
i++;
}
return 0;
}

void string_sort(char A[][13],int n,int &a, int&b){
int i, j;
a=b=0;
for (i = 0; i < n - 1; i++){
for (j = 0; j < n - i - 1;j++){
if (string_compare(A[j],A[j+1])==-1){a++; continue;}
else if(string_compare(A[j],A[j+1])==0){a++; continue;}
else {swap(A[i],A[j]); b++;}
}
}
}

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

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
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;
#define MAX 12 
int count1=0;
int count2=0;

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 s1[], char s2[]){
	char Temp[MAX];
    string_copy (Temp,s1);
    string_copy (s1,s2);
    string_copy (s2,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 A[][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++)
        {	
     		count1++;
            if (string_compare(A[j],A[j + 1])<0){
            	swap(A[j],A[j+1]);
            	count2++;
            }      
        }
        
    }
}

void print_array(char A[][MAX],int n){
	for(int i=0;i<n;i++){
		cout << A[i]<<" ";
	}

}

int main(){

	int n;
	cin >> n;
	n=n+1;
	char arr[n][MAX];
	for(int i=0;i<n;i++){
		cin.getline(arr[i],MAX);
	}
	string_sort(arr,n);
	print_array(arr,n);
	cout << endl <<count1<<" "<<count2;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
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 100
int stringcomp=0,stringswap=0;
void swap(char &var1,char &var2){
int temp=var1;
var1=var2;
var2=temp;
                                 }

int string_compare(char var1,char var2){
stringcomp++;
if(var1<var2){return 1;}
else if(var1>var2){return -1;}
else{return 0;}

                                         }
void string_sort(char met[][MAX],int n){

int i,j,k;
for(k=0;k<n;k++){
for(i=0;i<n-1;i++){
for(j=0;j<n-1;j++){

int comparison=string_compare(met[i][j],met[i+1][j]);
if(comparison==1){swap(met[i],met[i+1]);stringswap++;break; }
         }}}

                           }

int main(){
int n;
cin>>n;
char met[MAX][MAX];
for(int i=0;i<n;i++){
cin>>met[i];
                     }
string_sort(met,n);

for(int i=0;i<n;i++){
cout<<met[i]<<" ";   }
cout<<endl<<stringcomp<<" "<<stringswap<<endl;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
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 swap(int &a,int  &b){
int temp=a;a=b;b=temp;}
void string_sort(char A[][12], int n,int &c)
{
    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 (A[j][0] > A[j + 1][0])
               { swap(A[j], A[j + 1]);c+=1;}
		
        }
    }
}
int main(){
int n;
cin>>n;
char A[n][12];
for(int i=0;i<n;i++){
cin>>A[i];
A[i][11]='\0';}
int count=0;int c=0;
for(int i=0;i<n;i++){
for(int j=n-1;j>i;j--){
string_compare(A[i],A[j]);
count+=1;}
}
string_sort(A,n,c);
for(int i=0;i<n;i++){
cout<<A[n-1-i]<<" ";}
cout<<count<<endl;
cout<<c;}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
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;
void

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
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 11

int  string_compare(char str[m],char str[n]){
}




















int main(){

int n;
cin>>n;
char str[n][MAX];
for(int i=0;i<n;i++){
	cin>>str[i];

}

}













































}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
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;

void input(char *a, int n){
for (int i=0; i<n; i++) cin>>a[i];
}

int string_compare(char *a, char *b, int n, int &c){
for (int i=0; i<n; i++){
c++;
if (a[i]<b[i]) return 1;
if (a[i]>b[i]) return -1;
}
return 0;
}

int string_sort(char *a, int n, int& c){
int s=0;
for (int i=n; i>0; i--){
for (int j=0; j<i-1; j++){
c++;
if (int(a[j])<int(a[j+1])) {
int t = a[j];
a[j]=a[j+1];
a[j+1]=t;
s++;}
}}
for (int i=0; i<n; i++) cout<<a[i];
cout<<endl;
return s;	
}

int main(){

unsigned int n;
int c=0;
cin>>n;
char arr[10][n];
input(arr[1], n);
input(arr[2], n);
cout<<string_compare(arr[1],arr[2],n, c)<<endl;
int sw=string_sort(arr[1], n, c);
sw+=string_sort(arr[2],n, c);
cout<<"number of string_compare operations = "<<c<<endl;
cout<<"number of string swaps = "<<sw<<endl;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C