if the string is college
the output must be
c=1
o=1
l=2
e=2
g=1
it counts that how many a letter does it used
thnk you ^^
|
Newbie Member
|
|
| 11Aug2009,14:15 | #1 |
|
can someone solve my problem
if the string is college the output must be c=1 o=1 l=2 e=2 g=1 it counts that how many a letter does it used thnk you ^^
|
|
Mentor
|
![]() |
| 18Aug2009,01:59 | #2 |
|
I'd probably use an array of 26 ints initialised to zero, then for each letter encountered increment the relevant element. Pseudocode:
Code:
int arr[26] initialise to zero
char *str="college"
for each character c in str
arr[str[c]-'a']++
end for
for each element e of arr
if non-zero
print the letter (e+'a') and the count
end if
end for
|