• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            f(sixleaves) = sixleaves

            重劍無鋒 大巧不工

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              95 隨筆 :: 0 文章 :: 7 評論 :: 0 Trackbacks
            題目其實很簡單,答題意思就是從管道讀取一組文件名,并且按照字典序排列,但是輸入的時候按列先輸出,再輸出行。而且每一行最多60個字符。而每個文件名所占的寬度為最大文件名的長度加2,除了輸出在最右邊的文件名的寬度是最大文件名長度之外。編程實現這個功能,這就是Unix系統下ls命令的一部分而已。具體實現如下。
            主要學習的技能要點就是如何用偏移位移法來按列輸出。如果一個矩陣n行m列,要按照列輸出。但是我們知道,編程時候,只能是for(行)在列。所以必須要有一個偏移量來計算這種偏移關系。x = rows * c + r;

             1 #include <iostream>
             2 #include <string>
             3 #include <algorithm>
             4 #include <vector>
             5 #include <cmath>
             6 
             7 using namespace std;
             8 
             9 vector<string> words;
            10 void print(const string &s, int len, char extra);
            11 int main() {
            12     
            13     
            14     int n;
            15     string w;
            16     
            17     while (cin >> n) {
            18         
            19         int max = 0;
            20         words.clear();
            21         for (int i = 0; i < n; i++) {
            22             cin >> w;
            23             string::size_type str_size = w.size();
            24             if (str_size > max) max = str_size;
            25             words.push_back(w);
            26         }
            27         int cols = (60 - max) / (max + 2) + 1;
            28         int rows = ceil(double(n) / cols);
            29         sort(words.begin(), words.end());
            30         print("", 60, '-');
            31         cout << endl;
            32         for(int r = 0; r < rows; r++) {
            33             
            34             for (int c = 0; c < cols; c++) {
            35                 
            36                 int idx = c * rows + r;
            37                 if (idx < n) print(words[idx],(c == cols - 1? max: max + 2), ' ');
            38                 
            39             }
            40             
            41             cout << endl;
            42             
            43         }
            44         
            45         
            46     }
            47     
            48     return 0;
            49     
            50 }
            51 
            52 void print(const string &s, int len, char extra) {
            53     
            54     cout << s;
            55     string::size_type str_size = s.size();
            56     for (int i = 0; i < len - str_size; i++) {
            57         cout << extra;
            58     }
            59 }
            posted on 2015-03-25 14:32 swp 閱讀(171) 評論(0)  編輯 收藏 引用 所屬分類: algorithm
            色综合久久88色综合天天| 久久99热这里只有精品国产| 国产成人精品久久一区二区三区| 99久久中文字幕| 一本色道久久综合狠狠躁篇| 性做久久久久久久| 久久婷婷五月综合色99啪ak| 久久99精品久久久久久噜噜| 久久久老熟女一区二区三区| 久久香蕉超碰97国产精品| 国产精品99久久不卡| 久久久久亚洲AV片无码下载蜜桃| 久久精品国产只有精品66| 久久久久久九九99精品| 一级女性全黄久久生活片免费| 97久久精品无码一区二区天美| 狠狠色丁香久久婷婷综合蜜芽五月| 97久久超碰成人精品网站| 2021国内精品久久久久久影院| 亚洲一区中文字幕久久| 国内精品久久久久久久97牛牛| 久久乐国产综合亚洲精品| 国产精自产拍久久久久久蜜| 久久久精品2019免费观看| 久久久久亚洲AV无码去区首| 国产欧美久久一区二区| 久久精品黄AA片一区二区三区| 色偷偷偷久久伊人大杳蕉| 久久亚洲精品无码VA大香大香| 久久婷婷色香五月综合激情| 一97日本道伊人久久综合影院| 久久精品成人免费国产片小草| 国产精品美女久久久久av爽| 99久久国产综合精品五月天喷水| 久久综合狠狠色综合伊人| 亚洲综合精品香蕉久久网97| 一级做a爱片久久毛片| 色综合久久综合网观看| 狠狠干狠狠久久| 久久天天躁狠狠躁夜夜不卡| 久久久久久久精品成人热色戒|