zoukankan      html  css  js  c++  java
  • UVa

    看上去十分麻烦的一道题,但是看了看别人的写法感觉大神们写的无比简单。

    就是记一个每列单词的最大长度,然后剩下的事交给NB的iomanip头文件就好。

    stringsteam是一个神奇的东西。

    #include <iostream>
    #include <cstdio>
    #include <iomanip>
    #include <sstream>
    #include <string>
    #include <cstring>
    #include <vector>
    
    using namespace std;
    #define maxn 1000 + 100
    
    vector<string> code[maxn];
    int maxlen[maxn];
    
    int main()
    {
        string s;
        int cas = 0;
        while (getline(cin, s))
        {
            stringstream ss(s);//用这个字符串流可以从字符串中输入文件
            string word;
            int tot = 0;
            while(ss >> word)
            {
                maxlen[tot] = max(maxlen[tot], (int)word.size());
                code[cas].push_back(word);
                ++tot;
            }
            ++cas;
        }
    
        cout << setiosflags(ios :: left);
        for (int j = 0; j < cas; j++)
        {
            int i = 0;
            for (i; i < code[j].size()-1; i++)
                cout << setw(maxlen[i] + 1) << code[j][i];
    
            cout << code[j][i] << endl;
        }
    
    }
    
  • 相关阅读:
    nsis打包
    学习记录:ST表
    学习记录:快速幂
    学习记录:哈夫曼树
    学习记录:二叉树
    学习记录:康托展开 与 逆康托展开
    堆排序简介
    动态规划水题集
    lower_bound( ) 与 upper_bound( )
    琐碎的一点技巧
  • 原文地址:https://www.cnblogs.com/ruthank/p/9015032.html
Copyright © 2011-2022 走看看