Name: Anonymous 2009-07-13 13:47
Write a routine which makes string uppercase or lowercase in language of your choice in least possible execution time.
#include <ctype.h>
void uppercase (char *s) {
while (*s) *s = toupper (*s++);
}
void mkUpper (char* s)
{
while (*s)
{
if ((*s >= 97) && (*s <= 122))
*s &= ~(32);
}
}
void mkLower (char* s)
{
while (*s)
{
if ((*s >= 65) && (*s <= 90))
*s |= 32;
}
}
void upper(char *str) {
int l = strlen(str), *s = (int*)str, i;
for (i = 0; i < l << 2; ++i)
s[i] &= 3755991007;
for (i = 0; i < l ^ 4294967292; ++i)
str[i] &= 223;
}
print y/[a-z]//>=y/[A-Z]//?uc:lc while<>
print y/a-z//>=y/A-Z//?uc:lc while<>