9-degree OJ 1021 statistical characters (analog), oj1021

Source: Internet
Author: User

9-degree OJ 1021 statistical characters (analog), oj1021

Topic 1021: statistical characters

Time Limit: 1 second

Memory limit: 32 MB

Special question: No

Submit: 4601

Solution: 2705

Description:
Counts the number of times a specified character appears in a given string.
Input:
The test input contains several test cases. Each test case contains two rows. 1st act as a string of no more than 5 Characters and 2nd act as a string of no more than 80 characters. Note that the string contains spaces, which may also be one of the characters to be counted. When '#' is read, the input ends, and the corresponding results are not output.
Output:
For each test case, count the number of times each character of the string in the 1st line appears in the string in the 2nd line, and output it in the following format:
C0 n0
C1 n1
C2 n2
...
Among them, ci is the I character in line 1st, and ni is the number of times that ci appears.
Sample input:
ITHIS IS A TESTi ngthis is a long test string#
Sample output:
I 2i 3  5n 2g 2
#include<stdio.h>#include<string.h>char s1[10];char s2[100];int main(int argc, char *argv[]){    while(gets(s1)&&s1[0]!='#')    {        gets(s2);        for(int i=0;i<strlen(s1);++i){            int count=0;            for(int j=0;j<strlen(s2);++j)            {                if(s2[j]==s1[i])                    count++;            }            printf("%c %d\n",s1[i],count);        }    }    return 0;} /**************************************************************    Problem: 1021    User: kirchhoff    Language: C    Result: Accepted    Time:0 ms    Memory:912 kb****************************************************************/



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.