Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string.

Ex: If the input is:

n Monday
the output is:

1
Ex: If the input is:

z Today is Monday
the output is:

0
Ex: If the input is:

n It's a sunny day
the output is:

2
Case matters.

Ex: If the input is:

n Nobody
the output is:

0
n is different than N.





This is what i have so far.
#include
#include
using namespace std;

int main() {

char userInput;
string userStr;
int numCount;

cin >> userInput;
cin >> userStr;

while (numCount == 0) {
cout << numCount << endl;
numCount = userStr.find(userInput);

}
return 0;
}


Answers

Answer 1
Here is a Python program:

tmp = input().split(' ')
c = tmp[0]; s = tmp[1]
ans=0
for i in range(len(s)):
if s[i] == c: ans+=1

# the ans variable stores the number of occurrences
print(ans)

Related Questions

D-H public key exchange Please calculate the key for both Alice and Bob.
Alice Public area Bob
Alice and Bob publicly agree to make
N = 50, P = 41
Alice chooses her Bob
picks his
Private # A = 19 private #
B= ?
------------------------------------------------------------------------------------------------------------------------------------------
I am on Alice site, I choose my private # A = 19.
You are on Bob site, you pick up the private B, B and N should have no common factor, except 1.
(Suggest to choose B as a prime #) Please calculate all the steps, and find the key made by Alice and Bob.
The ppt file of D-H cryptography is uploaded. You can follow the steps listed in the ppt file.
Show all steps.

Answers

Answer:

See explaination

Explanation:

Please kindly check attachment for the step by step solution of the given problem.

Other Questions
Brownley Company has two service departments and two operating (production) departments. The Payroll Department services all three of the other departments in proportion to the number of employees in each. The Maintenance Department costs are allocated to the two operating departments in proportion to the floor space used by each. Listed below are the operating data for the current period: Service Depts. Production Depts. Payroll Maintenance Cutting Assembly Direct costs $ 20,400 $ 25,500 $ 76,500 $ 105,400 No. of personnel 15 15 45 Sq. ft. of space 10,000 15,000 The total cost of operating the Maintenance Department for the current period is: Tate is paid $17.35 per hour with time and a half overtime. What will his gross pay period in which he worked 35 hours one week and 44 hours next week for a total 79 hours? what is m equal to.4(m 13) 8 = 8 Which statement is true?A. Taxes are higher on short-term investments than long-term investments.B. Short-term investments are less prone to price volatility than long-term investments.C. Short-term investments require greater diversification than long-term investments.D. Short-term investments incur lower transaction fees than long-term investments.E. Short-term investments have a higher inflationary risk than long-term investments. Match each subject-verb agreement rule with an example of its use.sentence beginning with theresingular noun ending in scollective nounsingular noun with two partsphrase between subject and verb A Bowling ball is rolled down the alley with the constant velocity of 1.6 m/sec at an angle of 85 to the starting line, the position of the person throwing a bowling ball can be represented by the point (0,0). where is the ball after six seconds? Andre hit 46 balls at practice. He hit no fewer than 20 less than double the number of hits Jason had. Which inequality represents the situation if j represents the number of hits Jason had?46 minus 20 less-than 2 j2 j minus 20 less-than-or-equal-to 4646 minus 20 less-than-or-equal-to 2 j2 j minus 20 greater-than-or-equal-to 46 568,924,126 each digit stands for what Which values are solutions to the inequality belowCheck all that apply It would take a long time to read the lady, or the tiger? aloud, but this film tells entire story and under two minutes. What technique does the films director use? Simplify (-2x^3)2yy^9 Evaluate the expression 3 x{10 +1} +5. how did japan change during the Heian empire/period Which statement is an infrence about the odyssey? A rectangular prism has a length of 12in, a height of 5in, and a width of 8in. What is its volume, in cubic in? easy please quickly answer giving brainiest D-H public key exchange Please calculate the key for both Alice and Bob. Alice Public area Bob Alice and Bob publicly agree to make N = 50, P = 41 Alice chooses her Bob picks his Private # A = 19 private # B= ? ------------------------------------------------------------------------------------------------------------------------------------------ I am on Alice site, I choose my private # A = 19. You are on Bob site, you pick up the private B, B and N should have no common factor, except 1. (Suggest to choose B as a prime #) Please calculate all the steps, and find the key made by Alice and Bob. The ppt file of D-H cryptography is uploaded. You can follow the steps listed in the ppt file. Show all steps. 1 Traditional, barred cages are almost absent from modern zoos. 2 Instead, animals in modern zoos live in surroundings similar to their natural environment in the wild. 3 Artificial storms are designed, and deserts are constructed, to meet the needs of a wide variety of beasts, fish, and fowl. 4 Fish exhibits are particularly popular at zoos. 5 Tape recordings of familiar noises are used to soothe animals and help them adjust to new homes. 6 Gorillas, for example, often become sluggish in captivity. 7 They become more active when exposed to recordings of sounds that they would encounter in African mountain forests. Which sentence could you remove from the paragraph to improve its unity? How dose natural selection lead to evolution If a right triangle is rotated around one of its legs for 360 degrees, what three dimensional shape is produced?