zoukankan      html  css  js  c++  java
  • STL <cctype>

    http://www.cplusplus.com/reference/cctype/

    isalnum

    View Code
    /* isalnum example */
    /*Checks whether c is either a decimal digit or an uppercase or lowercase letter.*/
    #include <stdio.h>
    #include <cctype>
    int main ()
    {
      int i;
      char str[]="c3Po...";
      i=0;
      while (isalnum(str[i])) i++;
      printf ("The first %d characters are alphanumeric.\n",i);
      return 0;
    }

    isalpha

    View Code
    /* isalpha example */
    #include <stdio.h>
    #include <cctype>
    int main ()
    {
      int i=0;
      char str[]="C++";
      while (str[i])
      {
        if (isalpha(str[i])) printf ("character %c is alphabetic\n",str[i]);
        else printf ("character %c is not alphabetic\n",str[i]);
        i++;
      }
      return 0;
    }

    isdigit

    View Code
    /* isdigit example */
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    int main ()
    {
      char str[]="1776ad";
      int year, i=0;
      while(isdigit(str[i])) i++;
      printf("%d\n",i-1);
      if (isdigit(str[0]))
      {
        year = atoi (str);
        printf ("The year that followed %d was %d.\n",year,year+1);
      }
      return 0;
    }

    islower  and toupper

    View Code
    /* islower example */
    #include <stdio.h>
    #include <ctype.h>
    int main ()
    {
      int i=0;
      char str[]="Test String.\n";
      char c;
      while (str[i])
      {
        c=str[i];
        if (islower(c)) c=toupper(c);
        putchar (c);
        i++;
      }
      return 0;
    }

    ispunct

    View Code
    /* ispunct example */
    /*Checks whether c is a punctuation character*/
    #include <stdio.h>
    #include <cctype>
    int main ()
    {
      int i=0;
      int cx=0;
      char str[]="Hello, welcome!";
      while (str[i])
      {
        if (ispunct(str[i])) cx++;
        i++;
      }
      printf ("Sentence contains %d punctuation characters.\n", cx);
      return 0;
    }

    isupper and tolower

    View Code
    /* isupper example */
    #include <stdio.h>
    #include <cctype>
    int main ()
    {
      int i=0;
      char str[]="Test String.\n";
      char c;
      while (str[i])
      {
        c=str[i];
        if (isupper(c)) c=tolower(c);
        putchar (c);
        i++;
      }
      return 0;
    }
  • 相关阅读:
    Codeforces Beta Round #69 (Div. 2 Only)
    Codeforces Beta Round #67 (Div. 2)
    Codeforces Beta Round #65 (Div. 2)
    UmBasketella
    Codeforces Beta Round #63 (Div. 2)
    [agc004d]Teleporter
    [arc076f]Exhausted?
    NOIp模拟赛二十八
    CDQ分治笔记
    (noip模拟二十一)【BZOJ2500】幸福的道路-树形DP+单调队列
  • 原文地址:https://www.cnblogs.com/zhang1107/p/2971077.html
Copyright © 2011-2022 走看看