( 设计高效算法 ) 年龄排序 Age Sort Uva 11462
生活随笔
收集整理的這篇文章主要介紹了
( 设计高效算法 ) 年龄排序 Age Sort Uva 11462
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
( 設計高效算法 ) 年齡排序 Age Sort Uva 11462
posted on 2015-02-01 20:58 rex686568 閱讀(...) 評論(...) 編輯 收藏
可以使用整數排序法, 內存太小無法堆排序.
#include <cstdio> #include <cstring> using namespace std;int main(){unsigned int age[101];int n,temp;while (scanf("%d", &n) == 1 && n){memset(age, 0, sizeof(age));for (int i = 0; i < n; i++){scanf("%d", &temp);age[temp]++;}bool first = 1;for (int i = 1; i < 101; i++){for (int j = 0; j < age[i];j++){if (!first) printf("");else first = false;printf("%d", i);}}printf("\n");}}優化輸入輸出也可以提高效率,? 但是這個是最后考慮的優化要素.函數名前 的inline 相當于c的宏定義,? 降低大量函數引用消耗的時間.
使用cctype 中的 isdigit
posted on 2015-02-01 20:58 rex686568 閱讀(...) 評論(...) 編輯 收藏
轉載于:https://www.cnblogs.com/Pomodori/p/4316625.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的( 设计高效算法 ) 年龄排序 Age Sort Uva 11462的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网易云音乐竞品分析
- 下一篇: html标签缺省(自带)样式大全