zoukankan      html  css  js  c++  java
  • 计算字符个数

      今天终于放假啦,这不,风尘仆仆地从学校回到家中,洗澡淋浴,无比酣畅,同时准备写一会儿代码,预计到薄暮时分哦。

      刷到一道题目:计算字符个数:

    题目描述

    写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写

    eg: input:ABCDE  A output: 1

    Thinking 1:

    俗话说的好嘛,人生苦短,我用python.

    1 a=input().lower()
    2 b=input().lower()
    3 print(a.count(b))

     Thinking 2:

    my code:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main()
     4 {
     5     string s;
     6     char ch;
     7     while(getline(cin,s))
     8     {
     9         cin>>ch;
    10         int len=s.length();
    11         int count=0;
    12         for(int i=0;i<len;i++)
    13         {
    14             if(s[i]==tolower(ch)||s[i]==toupper(ch)||s[i]==ch)
    15              count++;
    16         }
    17         cout<<count<<endl;
    18     }
    19     return 0;
    20 }

    哈哈,收尾于此,诸君下午欢愉!龙龙刷题去喽!

  • 相关阅读:
    洛谷 P3521 [POI2011]ROT-Tree Rotations 解题报告
    洛谷 P1640 [SCOI2010]连续攻击游戏 解题报告
    vector-pop_back
    vector-push_back
    vector-push_back
    vector-max_size
    vector-max_size
    vector-insert
    vector-insert
    vector-front
  • 原文地址:https://www.cnblogs.com/dragondragon/p/11189422.html
Copyright © 2011-2022 走看看