CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: At college X, students and professors often use abbreviations for long titles of academic papers and projects. In this problem, you are asked to verify whether a given abbreviation matches the first letters of the words in a string, ignoring case. The abbreviation is valid only if it follows the exact order of the first letters of each word.

Examples:

For the words:
United Nations
united nations
United nations
united Nations

Valid abbreviations are:
UN, un, Un, uN

For the words:
Machine Learning college X

Valid abbreviations are:
MLIB (or any combination of upper and lowercase letters in the same order, such as mLiB).

Your Task

Main Program:

Write a C++ program that accepts four characters from the user and stores them in four character variables. Pass these characters to a function named isValidAbbreviation, which returns true if the abbreviation is valid, otherwise returns false. In the main function, print "yes" or "no" (lowercase letters) based on the returned value.

isValidAbbreviation Function:

1. Accept the words character by character as input.
2. Check whether the first letter of each word matches the corresponding abbreviation character (case insensitive).
3. Return false if there is any mismatch.
4. Return true if the entire abbreviation is correct.

To read character sequences with spaces:
First write:
cin >> noskipws;

Then a loop like the following may be used:
for (cin >> c; c != '\n'; cin >> c)

Output Format:

Print:
yes
or
no

accordingly.

Note:

- Do not print any extra messages such as:
  cout << "Enter a number";
  cout << "The computed answer is";
- Use cout only to print the final output.
- Do not print unnecessary spaces.
- Do not hard-code the solution.
- If any test case passes by simply printing with cout and without logic, marks will not be awarded.

Student submission:
#include <simplecpp>
#include <iostream>


char to_lower(char x){
	if(x >= 'A' && x<='Z')
		return('a'+x-'A');
	else
		return x;
};

bool isValidAbbreviation(char i, char j, char k, char l){
	i = to_lower(i);
	j = to_lower(j);
	k = to_lower(k);
	l = to_lower(l);
	cin>>noskipws;
	char I, J, K, L;
	char temp =' ';
	int count = 0;
	bool is_first = true;
	while(true){
		cin>>temp;
		if(temp == '\n'){
			if(count == 0){
				count++;
				continue;
			}
			break;
        }
		if(temp == ' '){
			is_first = true;
			continue;
		}
		if(is_first){
			if(count == 1)
			{
				I = to_lower(temp);
			}
			else if(count == 2){
				J = to_lower(temp);
			}
			else if(count == 3){
				K = to_lower(temp);
			}
			else if(count == 4){
				L = to_lower(temp);
			}
			count++;
			is_first = false;
			continue;
		}
	}
	if((I == i)&&(J == j) && (K == k) && (L == l)&&(count == 5))
		return true;
	else
		return false;
};

main_program{
	char a, b, c, d;
	cin>>a>>b>>c>>d;
	if(isValidAbbreviation(a, b, c, d))
		cout<<"yes";
	else
		cout<<"no";
}

Grading criterion: main: Print Yes or No
Rating A: Correctly prints yes or no according to the function output

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: A
Problem: At college X, students and professors often use abbreviations for long titles of academic papers and projects. In this problem, you are asked to verify whether a given abbreviation matches the first letters of the words in a string, ignoring case. The abbreviation is valid only if it follows the exact order of the first letters of each word.

Examples:

For the words:
United Nations
united nations
United nations
united Nations

Valid abbreviations are:
UN, un, Un, uN

For the words:
Machine Learning college X

Valid abbreviations are:
MLIB (or any combination of upper and lowercase letters in the same order, such as mLiB).

Your Task

Main Program:

Write a C++ program that accepts four characters from the user and stores them in four character variables. Pass these characters to a function named isValidAbbreviation, which returns true if the abbreviation is valid, otherwise returns false. In the main function, print "yes" or "no" (lowercase letters) based on the returned value.

isValidAbbreviation Function:

1. Accept the words character by character as input.
2. Check whether the first letter of each word matches the corresponding abbreviation character (case insensitive).
3. Return false if there is any mismatch.
4. Return true if the entire abbreviation is correct.

To read character sequences with spaces:
First write:
cin >> noskipws;

Then a loop like the following may be used:
for (cin >> c; c != '\n'; cin >> c)

Output Format:

Print:
yes
or
no

accordingly.

Note:

- Do not print any extra messages such as:
  cout << "Enter a number";
  cout << "The computed answer is";
- Use cout only to print the final output.
- Do not print unnecessary spaces.
- Do not hard-code the solution.
- If any test case passes by simply printing with cout and without logic, marks will not be awarded.

Student submission:
#include<simplecpp>
bool isValid(char c1, char c2, char c3, char c4){
    cin >> noskipws;
    char test;
    int numbits=32;
    
    bool b1=0,b2=0,b3=0,b4=0;
    int i=1;
    cin>>test;
    for(cin>>test; test!='\n'; cin>>test){
        test =test|numbits;
        if(i>8){
            return false;
        }
        if(i==1){
            
            if((test)==(c1)){
                b1=true;
            }
            i++;
        }
        if(i==3){
            if((test)==(c2)){
                b2=true;
            }
            i++;
        }
        if(i==5){
            if((test)==(c3)){
                b3=true;
            }
            i++;
        }
        if(i==7){
            if((test)==(c4)){
                b4=true;
            }
            i++;
        }
        if(test==' '){
            i++;
        }
    }
    if(b1 && b2 && b3 && b4){
        return true;
    }
    return false;
}
main_program{
    int numbits=32;
    char c1,c2,c3,c4;
    cin>>c1>>c2>>c3>>c4;
    c1=c1|numbits; c2=c2|numbits; c3=c3|numbits; c4=c4|numbits;
    cout<<((isValid(c1, c2, c3, c4))? "yes":"no");
}

Grading criterion: main: Print Yes or No
Rating A: Correctly prints yes or no according to the function output

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: A
Problem: At college X, students and professors often use abbreviations for long titles of academic papers and projects. In this problem, you are asked to verify whether a given abbreviation matches the first letters of the words in a string, ignoring case. The abbreviation is valid only if it follows the exact order of the first letters of each word.

Examples:

For the words:
United Nations
united nations
United nations
united Nations

Valid abbreviations are:
UN, un, Un, uN

For the words:
Machine Learning college X

Valid abbreviations are:
MLIB (or any combination of upper and lowercase letters in the same order, such as mLiB).

Your Task

Main Program:

Write a C++ program that accepts four characters from the user and stores them in four character variables. Pass these characters to a function named isValidAbbreviation, which returns true if the abbreviation is valid, otherwise returns false. In the main function, print "yes" or "no" (lowercase letters) based on the returned value.

isValidAbbreviation Function:

1. Accept the words character by character as input.
2. Check whether the first letter of each word matches the corresponding abbreviation character (case insensitive).
3. Return false if there is any mismatch.
4. Return true if the entire abbreviation is correct.

To read character sequences with spaces:
First write:
cin >> noskipws;

Then a loop like the following may be used:
for (cin >> c; c != '\n'; cin >> c)

Output Format:

Print:
yes
or
no

accordingly.

Note:

- Do not print any extra messages such as:
  cout << "Enter a number";
  cout << "The computed answer is";
- Use cout only to print the final output.
- Do not print unnecessary spaces.
- Do not hard-code the solution.
- If any test case passes by simply printing with cout and without logic, marks will not be awarded.

Student submission:
#include <simplecpp>

void capitalize(char &a){
	if (a>='a'){
		a+='A'-'a'; 
	}
}

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

bool isValidAbbreviation(char a, char b, char c, char d){
	cin>>noskipws;
	int i=0;
	bool ans=true;
	char prev_ch=' ', ch, let, trash,flet;
	cin>>trash;	
	for (cin>>flet; ch !='\n';cin>>ch){
		if (prev_ch == ' '){
			if (!i) let=ch;
			else let=flet;
			capitalize(let);
			if (let!=a) return false;
			swap(a,b);swap(b,c);swap(c,d);
		}
		prev_ch = ch;
		++i;
	}
	if (i!=3) return false;
	return ans;
}

main_program{
	char a,b,c,d;
	cin>>a>>b>>c>>d;
	bool ans;
	capitalize(a); capitalize(b); capitalize(c); capitalize(d);
	ans = isValidAbbreviation(a,b,c,d);
	if (ans) cout<<"yes";
	else cout<<"no"; 
}

Grading criterion: main: Print Yes or No
Rating A: Correctly prints yes or no according to the function output

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: A
Problem: At college X, students and professors often use abbreviations for long titles of academic papers and projects. In this problem, you are asked to verify whether a given abbreviation matches the first letters of the words in a string, ignoring case. The abbreviation is valid only if it follows the exact order of the first letters of each word.

Examples:

For the words:
United Nations
united nations
United nations
united Nations

Valid abbreviations are:
UN, un, Un, uN

For the words:
Machine Learning college X

Valid abbreviations are:
MLIB (or any combination of upper and lowercase letters in the same order, such as mLiB).

Your Task

Main Program:

Write a C++ program that accepts four characters from the user and stores them in four character variables. Pass these characters to a function named isValidAbbreviation, which returns true if the abbreviation is valid, otherwise returns false. In the main function, print "yes" or "no" (lowercase letters) based on the returned value.

isValidAbbreviation Function:

1. Accept the words character by character as input.
2. Check whether the first letter of each word matches the corresponding abbreviation character (case insensitive).
3. Return false if there is any mismatch.
4. Return true if the entire abbreviation is correct.

To read character sequences with spaces:
First write:
cin >> noskipws;

Then a loop like the following may be used:
for (cin >> c; c != '\n'; cin >> c)

Output Format:

Print:
yes
or
no

accordingly.

Note:

- Do not print any extra messages such as:
  cout << "Enter a number";
  cout << "The computed answer is";
- Use cout only to print the final output.
- Do not print unnecessary spaces.
- Do not hard-code the solution.
- If any test case passes by simply printing with cout and without logic, marks will not be awarded.

Student submission:
#include <simplecpp>
bool isValidAbbreviation(char c1,char c2,char c3,char c4){
    bool m,k,n= true;
    
    if(c1 > 'A' && c1 < 'Z'){
        c1 = c1 +32;
    }
    if(c2 >'A'&& c2 < 'Z'){
        c2 = c2+32;
    }
    if(c3 > 'A' && c2 < 'Z'){
        c3 = c3 +32;
    }
    if(c4 > 'A' && c4 < 'Z'){
        c4 = c4 + 32;
    }
    
    for(int x = 0; x<5;++x){
        char c;
        if(x ==0){
            c = c1;
        }
        if(x ==1){
            c = c2;
        }
        if(x==2){
            c =c3;
        }
        else{
            c = c4;
        }

        char in;
        cin>>noskipws;
        for(cin>>in; in != '\n'; cin>>in){
           if(in > 'A' && in < 'Z'){
            in = in +32;
           }
           if(in == c && x == 0){
            m = true;
            break;
           }
           else{
            m = false;
           }
           
        }
        k = m && n;
        n = m;
        
    }
    return (k);
}
main_program{
    char s1,s2,s3,s4;
    cin>>s1>>s2>>s3>>s4;
   if(isValidAbbreviation(s1,s2,s3,s4)){

    cout<<"yes";
   }
   else{
    cout<<"no";
   }  
}

Grading criterion: main: Print Yes or No
Rating A: Correctly prints yes or no according to the function output

Rating B: some issue
Rating C: major issue
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take the number n and an array A of n numbers as input from the user. The program should then contain a function which determines whether the array is in strictly increasing order (in which case the function should return 1), or else determine whether the array is in strictly decreasing order (in which case the function should return 2), and return 3 otherwise. The format of the function is int isIncreasingDecreasing (int *A, int n). The program should then print the value returned by the function on a new line. You must implement this via a function, otherwise you will get no credit. For simplicity, assume that all entries in the array are unique.

Input Format - Non-negative integer n and an array A of n elements
Output Format - The value 1,2 or 3 as described above. 
Constraints
1 <= n < 25

Sample input - 33 4 2
Sample output - 3

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

int isIncDec(int *A, int n){
int inc,dec;
inc = 0;
dec = 0;
for(int i = 0; i<n-1; i++){
if(A[i] < A[i+1]){
inc++;
}
if(A[i] > A[i+1]){
dec++;
}
}
if (inc == n-1) return 1;
if (dec == n-1 && inc != n-1) return 2;
if(inc != n-1 && dec != n-1) return 3;
}

int main(){
int n;
cin >> n;
int A[n];
for(int i = 0; i < n; i++){
cin >> A[i];
}
cout << isIncDec(A,n);
}

Grading criterion: Should be done in one scan of array
Rating A: If it is done in one scan
Rating B: If it isn't done in one scan
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to take the number n and an array A of n numbers as input from the user. The program should then contain a function which determines whether the array is in strictly increasing order (in which case the function should return 1), or else determine whether the array is in strictly decreasing order (in which case the function should return 2), and return 3 otherwise. The format of the function is int isIncreasingDecreasing (int *A, int n). The program should then print the value returned by the function on a new line. You must implement this via a function, otherwise you will get no credit. For simplicity, assume that all entries in the array are unique.

Input Format - Non-negative integer n and an array A of n elements
Output Format - The value 1,2 or 3 as described above. 
Constraints
1 <= n < 25

Sample input - 33 4 2
Sample output - 3

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
int isIncreasingDecreasing(int* A, int n){
	int p=0;int a,b;
	for(int j=1;j<n;j++){
	if(A[p]>A[j]){ a=1; p=j;}
	else{ a=0; break;}
	}
	for(int j=1;j<n;j++){
	if(A[p]<A[j]){ b=1; p=j;}
	else{b=0;break;}
	}
	if(a==0 && b==1)return 1;
	if(a==1 && b==0)return 2;
	else return 3;
	}
int main(){
	int n;
	cin>>n;
	if(n>1 && n<26){
	int A[n];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	cout<< isIncreasingDecreasing(A,n);
	}
	else if(n==1)cout<<"1";
	
}

Grading criterion: Should be done in one scan of array
Rating A: If it is done in one scan
Rating B: If it isn't done in one scan
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take the number n and an array A of n numbers as input from the user. The program should then contain a function which determines whether the array is in strictly increasing order (in which case the function should return 1), or else determine whether the array is in strictly decreasing order (in which case the function should return 2), and return 3 otherwise. The format of the function is int isIncreasingDecreasing (int *A, int n). The program should then print the value returned by the function on a new line. You must implement this via a function, otherwise you will get no credit. For simplicity, assume that all entries in the array are unique.

Input Format - Non-negative integer n and an array A of n elements
Output Format - The value 1,2 or 3 as described above. 
Constraints
1 <= n < 25

Sample input - 33 4 2
Sample output - 3

Student submission:
#include<iostream>
using namespace std;
int isIncreasingDecreasing(int* A, int n)
{
int res = 3, i, flag = 0;
if(A[0] < A[1])
{
flag = 1;
for(i = 0;i<n-1;i++)
{
if(A[i]>=A[i+1])
{
flag = 0;
break;
}
}
if(flag == 1)
res = 1;
}
else if(A[0]>A[1])
{
flag = 1;
for(i = 0;i<n-1;i++)
{
if(A[i]<=A[i+1])
{
flag = 0;
break;
}
}
if(flag == 1)
res = 2;
}
return res;
}
int main()
{
int N;
cin >> N;
int array[N],i;
for(i = 0;i<N;i++)
cin >> array[i];
cout << endl << isIncreasingDecreasing(array,N);
return 0;
}

Grading criterion: Should be done in one scan of array
Rating A: If it is done in one scan
Rating B: If it isn't done in one scan
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to take the number n and an array A of n numbers as input from the user. The program should then contain a function which determines whether the array is in strictly increasing order (in which case the function should return 1), or else determine whether the array is in strictly decreasing order (in which case the function should return 2), and return 3 otherwise. The format of the function is int isIncreasingDecreasing (int *A, int n). The program should then print the value returned by the function on a new line. You must implement this via a function, otherwise you will get no credit. For simplicity, assume that all entries in the array are unique.

Input Format - Non-negative integer n and an array A of n elements
Output Format - The value 1,2 or 3 as described above. 
Constraints
1 <= n < 25

Sample input - 33 4 2
Sample output - 3

Student submission:
#include<iostream>
using namespace std;
int increasingdecreasing(int *a,int n)
{int j=0;int k=0;
for(int i=0;i<n-1;i++)
{if(a[i]<a[i+1])j++;
   }
  for(int i=n-1;i>0;i--)
{if(a[i]<a[i-1])k++;}
if(j==n-1)return 1;
else if(k==n-1)return 2;
else return 3; 
   
   
}
int main()
{int n;
cin>>n;
int element[n];
for(int i=0;i<n;i++)
{cin>>element[i];}
cout<<increasingdecreasing(element,n);
}

Grading criterion: Should be done in one scan of array
Rating A: If it is done in one scan
Rating B: If it isn't done in one scan
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take the number n and an array A of n numbers as input from the user. The program should then contain a function which determines whether the array is in strictly increasing order (in which case the function should return 1), or else determine whether the array is in strictly decreasing order (in which case the function should return 2), and return 3 otherwise. The format of the function is int isIncreasingDecreasing (int *A, int n). The program should then print the value returned by the function on a new line. You must implement this via a function, otherwise you will get no credit. For simplicity, assume that all entries in the array are unique.

Input Format - Non-negative integer n and an array A of n elements
Output Format - The value 1,2 or 3 as described above. 
Constraints
1 <= n < 25

Sample input - 33 4 2
Sample output - 3

Student submission:
#include<simplecpp>

int isIncreasingDecreasing (int *A, int n){
     bool inc=true,dec=true;
     for(int i=0;i<n-1;i++){
     if(A[i]>A[i+1]){inc=false;}
     }
     for(int i=0;i<n-1;i++){
     if(A[i]<A[i+1]){dec=false;}
     }
     if(inc){return 1;}
     else if (dec){return 2;}
     else return 3;
     }


main_program{
int n;
cin>>n;
int A[n];
for(int i=0;i<n;i++){
cin>>A[i];}
cout<<isIncreasingDecreasing(A,n);}

Grading criterion: Should be done in one scan of array
Rating A: If it is done in one scan
Rating B: If it isn't done in one scan
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take the number n and an array A of n numbers as input from the user. The program should then contain a function which determines whether the array is in strictly increasing order (in which case the function should return 1), or else determine whether the array is in strictly decreasing order (in which case the function should return 2), and return 3 otherwise. The format of the function is int isIncreasingDecreasing (int *A, int n). The program should then print the value returned by the function on a new line. You must implement this via a function, otherwise you will get no credit. For simplicity, assume that all entries in the array are unique.

Input Format - Non-negative integer n and an array A of n elements
Output Format - The value 1,2 or 3 as described above. 
Constraints
1 <= n < 25

Sample input - 33 4 2
Sample output - 3

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

void myswap(int& a, int& b){
	int temp=a;
	a=b;
	b=temp;
}

int argmax(int *A, int n){
	int maxindex=0;
	for (int j=1;j<n;j++){
		if (A[maxindex]<A[j]) maxindex=j;
	}
	return maxindex;
}

int argmin(int *A, int n){
	int minindex=0;
	for (int j=1;j<n;j++){
		if (A[minindex]>A[j]) minindex=j;
	}
	return minindex;
}


void increasingsort(int* A, int n, int* B){
	
	for (int i=n;i>1;i--){
		int maxindex=argmax(A,i);
		myswap(B[maxindex],B[i-1]);
	} 
}

void decreasingsort(int* A, int n, int* C){
	
	for (int i=n;i>1;i--){
		int minindex=argmin(A,i);
		myswap(C[minindex],C[i-1]);
	} 
}

int equal(int* A, int* B, int n){
	int x=0;
	for (int i=0; i<n; i++){
		if (A[i]==B[i]) x++; 
	}
	if (x==n) return(1);
	else return(2);
}

int isIncreasingDecreasing(int* A, int n){
	int B[n], C[n];
	for (int j=0;j<n;j++) {B[j]=A[j]; C[j]=A[j];}
	
	increasingsort(A,n,B);
	decreasingsort(A,n,C);
	int x=equal(A,B,n);
	int y=equal(A,C,n);
	if (x==1) {return 1;}
	else if (y==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];
	int a;
	a=isIncreasingDecreasing(A,n);
	cout<<endl<<a;	
}

Grading criterion: Should be done in one scan of array
Rating A: If it is done in one scan
Rating B: If it isn't done in one scan
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take the number n and an array A of n numbers as input from the user. The program should then contain a function which determines whether the array is in strictly increasing order (in which case the function should return 1), or else determine whether the array is in strictly decreasing order (in which case the function should return 2), and return 3 otherwise. The format of the function is int isIncreasingDecreasing (int *A, int n). The program should then print the value returned by the function on a new line. You must implement this via a function, otherwise you will get no credit. For simplicity, assume that all entries in the array are unique.

Input Format - Non-negative integer n and an array A of n elements
Output Format - The value 1,2 or 3 as described above. 
Constraints
1 <= n < 25

Sample input - 33 4 2
Sample output - 3

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

int isIncreasingDecreasing(int *A,int n)
{
  for(int i=0;i<n;i++)
	{
		if (A[i+1]>A[i]) return 1;
		else if (A[i+1]<A[i]) return 2;
		else return 3;
	}
	return A[n];
}

int main(){
int n;
cin>>n;
int a[n];
for (int i=0;i<n;i++)
{
	cin>>a[i];
}
cout<<isIncreasingDecreasing (a,n);
}

Grading criterion: Should be done in one scan of array
Rating A: If it is done in one scan
Rating B: If it isn't done in one scan
Rating C: 0
Rating D: 0
Assigned grade: A