《STL》— UVa10815 Andy's First Dictionary

UVa10815 Andy's First Dictionary

题意:输入一个文本,找出所有不同的单词(连续字母序列),按字典序从小到大输出。单词不分大小写。

 

#include<string>
#include<set>
#include<sstream>
#include<iostream> 
using namespace std;

set<string> dict;
string s, buf;

int main() 
{
  	while(cin >> s) 
	{
    	for(int i = 0; i < s.length(); i++)
      		if(isalpha(s[i])) 
			  	s[i] = tolower(s[i]);  
			else s[i] = ' ';
       stringstream ss(s);
       while(ss >> buf) 
	      	dict.insert(buf);
    }
  	for(set<string>::iterator it = dict.begin(); it != dict.end(); ++it)
    	cout << *it << "\n";
  	return 0;
}

 

isalpha

函数名称: isalpha

函数原型: int isalpha(char ch);

函数功能: 检查ch是否是字母.

函数返回: 是字母返回非0(在vs2015中为2) ,否则返回 0.

参数说明:

所属文件 <ctype.h>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

#include<stdio.h>

#include<ctype.h>

int main()

{

    char ch1='*';

    char ch2='a';

    if(isalpha(ch1)!=0)

        printf("%c is the ASCII alphabet\n",ch1);

    else

        printf("%c is not the ASCII alphabet\n",ch1);

    if(isalnum(ch2)!=0)

        printf("%c is the ASCII alphabet\n",ch2);

    else

        printf("%c is not the ASCII alphabet\n",ch2);

    return0;

}

iscntrl

函数名称: iscntrl

函数原型: int iscntrl(int ch);

函数功能: 检查ch是否控制字符(其ASCII码在0和0x1F之间,数值为 0-31).

函数返回: 是返回非0,否则返回 0.

参数说明:

所属文件: <ctype.h>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

#include<stdio.h>

#include<ctype.h>

char chars[]={ 'A',0x09,'Z'};

#define SIZE sizeof(chars)/sizeof(char)

int main()

{

    int i;

    for(i=0;i<SIZE;i++)

    {

        printf("Char%cis%saControlcharacter\n",

        chars[i],(iscntrl(chars[i]))?"":"not");

    }

    return 0;

}

isdigit

函数名称: isdigit

函数原型: int isdigit(char ch);

函数功能: 检查ch是否是数字(0-9)

函数返回: 是返回非0,否则返回0

参数说明:

所属文件: <ctype.h>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

#include<stdio.h>

#include<ctype.h>

int main()

{

char ch1='1';

char ch2='a';

if(isdigit(ch1)!=0)

printf("%c is the ASCII number\n",ch1);

else

printf("%c is not the ASCII number\n",ch1);

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值