發表於 C++CPE考古題UVA一顆星

【CPE】UVA 10062 Tell me the frequencies!一星必考題 by C++

10062 Tell me the frequencies!

簡易翻譯和條件:

題目要求將輸入的字串中的字元按照題目要求的規則排序 ( 按照 ascii 與出現次數 )

這題也是一題給C++初學者寫的題目喔!很好的練習題

講道排序就是使用 algorithm 這個 Library ,這個是直覺反應一定不用多說的吧~

在這一題中排序的判斷需要用到 ascii 與 出現次數來排序,既然會用到兩個屬性,所以我會使用 struct 來裝載資料。

判斷的 compare function 就按照題目敘述做吧~ ( 自己練英文看懂題目吧! )
(底下程式碼的 c 代表著 ascii 的數值)

如果有任何問題或是你有更好的寫法歡迎再下面留言討論喔!
我們下一題見啦!

程式碼:

struct alpha{
    int c;
    int count;
};

inline bool gt(alpha a, alpha b){
    if(a.count != b.count)
    return a.count <b> b.c;
}

//  sort array via algorithm sort
sort(arr, arr+256, gt);
UVA 10062 Tell me the frequencies!
UVA 10062 Tell me the frequencies! 題目

作者:

一位 熱愛資工領域、喜歡好笑事物、偶爾打打網球 的學生 ! For A Better Me!

發表迴響

Please log in using one of these methods to post your comment:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.