Task Description
題目給定字串後,找出各個字元之 ASCII,並按照出現頻率由低到高印出。
若頻率相同,則以 ASCII 較大者先印出。
提示:
宣告字串: char str[128]; ,字串為字元陣列。
讀入字串: get(str); , str為讀入值。
輸出字串: printf(“%s”, str);
Hint
main.c
撰寫程式碼後對應上傳。12345678910111213141516171819202122232425262728293031 #include <stdio.h>#include <string.h>#include <limits.h>#include <stdlib.h> typedef struct pair { int frequency; char charASCII;} pair; void print(pair* myData){ int i; for (i=0 ; i<95 ; i++) (myData[i].frequency==0)?printf(""):printf("%d %d\n",myData[i].charASCII,myData[i].frequency);} int main(){ struct pair* myData=(struct pair*)malloc(95*sizeof(struct pair)); int i, len, flag=0; char str[9999]; while (gets(str)!=NULL) { if (flag!=0) printf("\n"); flag++; / add your code / print(myData); } return 0;}
Input Format
輸入多組字串,需判斷輸入結尾
Output Format
印出ASCII和頻率,ASCII和頻率之間空一格,每組之間空一行
Sample Input
12 AAABBC122333
Sample Output
123456789 67 166 265 3 49 150 251 3 // 這行與結果無關,為了顯示上一行的空白