问:在字符串中计算标点符号总数的程序。

2025 年 1 月 8 日 | 3 分钟阅读

在此程序中,需要打印出字符串的所有子集。字符串的子集是存在于字符串中的字符或字符组。例如,字符串“FUN”的所有可能子集将是F、U、N、FU、UN、FUN

算法

  1. 定义一个字符串。
  2. 如果字符串中的任何字符与 (! , . , ' , - , " , ? , ; ) 匹配,则计数加1。
  3. 打印计数。

复杂度

O(n)

解决方案

Python

输出

Total number of punctuation characters exists in string: 
4

C

输出

Total number of punctuation characters exists in string: 4

JAVA

输出

Total number of punctuation characters exists in string: 4

C#

输出

Total number of punctuation characters exists in string: 4

PHP

输出

Total number of punctuation characters exists in string: 4
 
下一个主题程序列表