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****************************************************************/