isupper
原型:extern int
isupper(int c);
头文件:<cctype>(旧版本的编译器使用<
ctype.h>)
功能:判断
字符c是否为大写英文字母
说明:当参数c为大写英文字母(A-Z)时,返回非零值,否则返回零。
附加说明: 此为
宏定义,非真正函数。
islower
islower(测试
字符是否为小写字母)
相关函数
isalpha,
isupper
表头文件
#include<cctype>(旧版本的编译器使用<
ctype.h>)
定义函数
int islower(int c)
函数说明
检查参数c是否为小写英文字母。
返回值
若参数c为小写英文字母,则返回TRUE,否则返回NULL(0)。
附加说明:此为宏定义,非真正函数。
题目中的运用:(讨论区)
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX 5000 + 2
char s[MAX];
int test(int i, int j)
{
int count = 0;
while(i <= j)
{
if(!isalpha(s[i]))
{
++i;
continue;
}
if(!isalpha(s[j]))
{
--j;
continue;
}
if(toupper(s[i]) == toupper(s[j]))
{
++count;
if(i != j) ++count;
++i;
--j; //顺序与上面不能颠倒
continue;
}
return 0;
}
return count;
}
int main()
{
int t, len, max, maxl, maxr, temp;
scanf("%d", &t);
getchar();
while(t--)
{
gets(s);
len = strlen(s);
max = maxl = maxr = 0;
for(int i = 0; i != len; ++i)
{
if(!isalpha(s[i]))
continue;
for(int j = i + 1; j != len; ++j)
{
if(!isalpha(s[j]))
continue;
if(toupper(s[i]) == toupper(s[j]))
{
if(temp = test(i, j))
if(temp > max)
max = temp, maxl = i, maxr = j;
}
}
}
if(max)
{
s[maxr + 1] = '\0';
puts(s + maxl);
}
else
{
int i;
for(i = 0; i != len; ++i)
{
if(!isalpha(s[i]))
continue;
printf("%c\n", s[i]);
}
}
}
return 0;
}