iT邦幫忙

0

求解 拜託各位

LQe 2019-04-09 21:00:101969 瀏覽

Write a C code to ask the user to enter an English word and count the occurrence of each
letter (ignore the case). For example, if the user enters the word ‘Tomorrow’ then your code
should output the following result:
T(1), O(3), M(1), R(2), W(1)

froce iT邦大師 1 級 ‧ 2019-04-09 22:00:23 檢舉
Do your homework self!
ccutmis iT邦高手 2 級 ‧ 2019-04-09 22:22:35 檢舉
>>Please Enter a Ehglish word:
>>Tomorrow
>>T(1),O(3),R(2),W(1)
小魚 iT邦大師 1 級 ‧ 2019-04-09 22:56:52 檢舉
Give Up
G(1) I(1) V(1) E(1) U(1) P(1)
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

4
海綿寶寶
iT邦大神 1 級 ‧ 2019-04-09 22:43:05

參考資料來源

    #include <stdio.h>
    #include <string.h>
     
    int main()
    {
       char string[100];
       int c = 0, count[26] = {0}, x;
       int index = 1, idx[26] = {0};
     
       printf("Enter a string\n");
       gets(string);
     
       while (string[c] != '\0') {
       /** Considering characters from 'a' to 'z' only and ignoring others. */
     
          if (string[c] >= 'a' && string[c] <= 'z') {
             x = string[c] - 'a';
             count[x]++;
          }
          if (string[c] >= 'A' && string[c] <= 'Z') {
             x = string[c] - 'A';
             count[x]++;
          }
     
          if(idx[x]==0) {idx[x]=index++;}
          c++;
       }
     
        for (int i=1;i<index;i++) {
            for (int j=0;j<26;j++) {
               if (idx[j]==i) {
                   if(i>1){printf(",");}
                   printf("%c(%d)", j + 'A', count[j]);
                   break;
               }   
            }
        }
     
       return 0;
    }
小魚 iT邦大師 1 級 ‧ 2019-04-10 07:53:06 檢舉

海綿寶寶也太好心了吧,
對這種伸手牌的人...

納貝 iT邦新手 1 級 ‧ 2019-04-10 13:16:06 檢舉

我大學的時候要是早點來註冊會員就好了

打雜工 iT邦研究生 1 級 ‧ 2019-04-13 15:19:24 檢舉

這樣會寵壞年輕學子的~

0
舜~
iT邦高手 1 級 ‧ 2019-04-10 10:26:26

假設您不是伸手牌,只是看不懂英文...

幫您翻譯題目:

編寫C代碼,讓用戶輸入英文單詞並計算每個字母的出現次數(忽略大小寫)。
例如,如果用戶輸入單詞'Tomorrow',
那麼您的代碼應輸出以下結果:
T(1), O(3), M(1), R(2), W(1)

答案請參考海綿寶寶~~

看更多先前的回應...收起先前的回應...
小魚 iT邦大師 1 級 ‧ 2019-04-10 10:58:51 檢舉

我覺得,
現在只要丟到Google,
再稍微理解一下,
就可以了,
沒什麼看不懂英文的...
Chrome還可以幫忙翻譯網頁...

納貝 iT邦新手 1 級 ‧ 2019-04-10 13:17:23 檢舉

回答可以賺10分.....多多益善總是好事吧...我猜

ccutmis iT邦高手 2 級 ‧ 2019-04-10 16:06:35 檢舉

/images/emoticon/emoticon01.gif

小魚 iT邦大師 1 級 ‧ 2019-04-11 10:40:48 檢舉

喔,也對,我已經過了需要點數的階段了

chwei_wu iT邦新手 4 級 ‧ 2019-04-11 16:11:48 檢舉

...重點是...發問者沒給海綿寶寶最佳解答~~~

我要發表回答

立即登入回答