[ create a new paste ] login | about

Link: http://codepad.org/7N6ZgzCl    [ raw code | output | fork ]

C++, pasted on Feb 20:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
 
template<typename T>
bool is_bigger(T* arr, size_t size) {
	return all_of(arr+1,arr+size,[](T& elem){return *(&elem-1)<elem;});
}
 
bool is_bigger(char *str) {
	return is_bigger(str,strlen(str));
}
 
int main() {
	int a[]={1,4,6,8};
	int b[]={1,4,6,3};
	char c[10] = "abceghopqr";
	char d[10] = "abceghfxyz";
	float e[] = {1.0,7.9,32.3,1e6};
	if(is_bigger(a,sizeof(a)/sizeof(a[0]))){
		cout <<"A"<<endl;
	}
	if(is_bigger(b,sizeof(b)/sizeof(b[0]))){
		cout <<"B"<<endl;
	}
	if(is_bigger(c)){
		cout <<"C"<<endl;
	}
	if(is_bigger(d)){
		cout <<"D"<<endl;
	}
	cout<< "BONUS: ";
	if(is_bigger(e,sizeof(e)/sizeof(e[0]))){
		cout <<"E"<<endl;
	}
	return 0;
}


Output:
1
2
3
In function 'bool is_bigger(T*, size_t)':
Line 8: error: expected primary-expression before '[' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: