C++ 统计输入的句子有多少英文字母

// ConsoleApplication1.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int countnubstr(string str)
{
int returnnum = 0;
for (int i = 0; i<str.length(); i++)
{
if ((str[i] >= ‘a‘ && str[i] <= ‘z‘) || (str[i] >= ‘A‘ && str[i] <= ‘Z‘))
{
returnnum++;
}
}
return returnnum;
}

void main()
{
string str;
cout << "Please input English Line" << endl;
//流输入一串英文句子。
getline(cin,str);
cout << endl<< "There is " << countnubstr(str) << "noumber words int this English Line" << endl;
getchar();
}

原文地址:https://www.cnblogs.com/anyeliuguang/p/10887596.html

时间: 2024-08-01 19:24:56

C++ 统计输入的句子有多少英文字母的相关文章

如果输入的不是英文字母或者数字或者汉字,则返回false

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string input = textBox1.Text.Trim(); if (chkInput(input)) MessageBox.Show("true"); else MessageBox.Show("

Python(30)_统计输入的字符串有多少数字

#-*-coding:utf-8-*- ''' 统计用户输入的字符串中有几个数字 ''' # numList = ['0','1','2','3','4','5','6','7','8','9'] s = input('请输入字符串:') count = 0 for i in s: if i in numList: count +=1 print(count) Python(30)_统计输入的字符串有多少数字 原文地址:https://www.cnblogs.com/sunnybowen/p/1

28、editText只输入英文字母和&#39;-&#39;,用于授权码输入

1 InputFilter filter = new InputFilter() { 2 3 @Override 4 public CharSequence filter(CharSequence source, int start, int end, 5 Spanned dest, int dstart, int dend) { 6 // TODO Auto-generated method stub 7 for (int i = start; i < end; i++) 8 { 9 //在这

【转】正则表达式 匹配中文,英文字母和数字及_的写法!同时控制长度

匹配中文:[\u4e00-\u9fa5] 英文字母:[a-zA-Z] 数字:[0-9] 匹配中文,英文字母和数字及_: ^[\u4e00-\u9fa5_a-zA-Z0-9]+$ 同时判断输入长度:[\u4e00-\u9fa5_a-zA-Z0-9_]{4,10} ^[\w\u4E00-\u9FA5\uF900-\uFA2D]*$ 1.一个正则表达式,只含有汉字.数字.字母.下划线不能以下划线开头和结尾:^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$  其中:^

由数字、26个英文字母、下划线或汉字的正则表达式

1.由数字.26个英文字母或者下划线组成的字符串: ^[0-9a-zA-Z_]{1,}$ 2.非负整数(正整数 + 0 ): ^/d+$ 3. 正整数: ^[0-9]*[1-9][0-9]*$ 4.非正整数(负整数 + 0): ^((-/d+)|(0+))$ 5. 负整数 : ^-[0-9]*[1-9][0-9]*$ 6.整数: ^-?/d+$ 7.非负浮点数(正浮点数 + 0): ^/d+(/./d+)?$ 8.正浮点数 : ^(([0-9]+/.[0-9]*[1-9][0-9]*)|([0-

正则表达式 匹配中文,英文字母和数字及_的写法!同时控制长度

匹配中文:[\u4e00-\u9fa5] 英文字母:[a-zA-Z] 数字:[0-9] 匹配中文,英文字母和数字及_: ^[\u4e00-\u9fa5_a-zA-Z0-9]+$ 同时判断输入长度:[\u4e00-\u9fa5_a-zA-Z0-9_]{4,10} ^[\w\u4E00-\u9FA5\uF900-\uFA2D]*$ 1.一个正则表达式,只含有汉字.数字.字母.下划线不能以下划线开头和结尾:^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$  其中:^

C#根据用户输入字符串,输出大写字母有几个,小写字母有几个

static void Main(string[] args) { // 根据用户输入字符串,输出大写字母有几个,小写字母有几个. Console.WriteLine("请输入一行英文代码"); string s = Console.ReadLine(); //用一个字符串接受输入值. int i = 0; int j = 0;// i是大写个数, j是小写个数. foreach (char s1 in s) { if (s1 >= 'A' && s1 <=

C语言:统计输入的一行英文句子中的字母及单词个数,带注解!

//通过键盘输入一行英文句子,统计其中的英文字母和单词的数量,单词之间用空格分开(标点符号不算单词):#include<stdio.h> #include<string.h>#include<stdlib.h>main(){ char string[100];//根据拟从键盘输入的字串的长度需要适当调整,要避免输入的长度超出设定的范围.  char c; int i, num=0,sum=0,word=0; //定义 word 用来指示一个单词是不是结束或新单词是否开始

编写一个程序,统计输入字符串中每一个小写英文字母出现的次数

import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/1 22:18 * @description: * @version:$ */ /*编写一个程序,统计输入字符串中每一个小写英文字母出现的次数*/ public class page0901 { public static void main(String[] args) { /*首先,输入一段字符串作为字符数组*/ System.out.p