• UVA 1593 Alignment of Code


    题意:

    给出若干行字符串和 空格,输出:
    开头,结尾都没有空格;每一行 两个字符串之间最少有一个空格,每一列字符串 左对齐。

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring> // for memset
    #include <vector> // vector<int>().swap(v);
    #include <set> // multiset set<int,greater<int>> //big->small
    #include <map>
    #include <stack> // top()
    #include <queue> // front() // priority_queue<T,vector<T>,greater<T> >
    #include <cmath> // auto &Name : STLName  Name.
    #include <utility>
    #include <sstream>
    #include <string> // __builtin_popcount (ans); // 获取某个数二进制位1的个数
    #include <iomanip> 
    #include <cstdlib> // rand()
    
    #define IOS ios_base::sync_with_stdio(0); cin.tie(0)
    #define lowbit(x) (x&(-x))
    using namespace std;
    typedef long long ll;
    
    const double PI=acos(-1.0);
    const int INF = 0x3f3f3f3f;
    const int MAX_N = 1e3 + 400;
    const int MOD = 1000000007;
    
    string s,st;
    vector<string> lines[MAX_N];
    int row=0;
    int maxcol[MAX_N];
    
    int main(void)
    {
        while (getline(cin ,s)) {
            stringstream input(s);
            while (input >>st) { // 空格分割
                maxcol[lines[row].size()] = max(maxcol[lines[row].size()], (int)st.size()); 
                lines[row].push_back(st); // 保存单词
            }
            row ++;
        }
        for (int i = 0; i < row; i ++) {
            for (int j = 0; j < lines[i].size(); j ++) {
                st = lines[i][j]; 
                if (j != lines[i].size()-1) st += string(maxcol[j]-st.size()+1, ' '); // 补空格
                printf("%s", st.c_str());
            }
            puts("");
        }
    
        return 0;
    }

      

  • 相关阅读:
    Django(03):Django 创建第一个项目
    Django(02):Django安装
    Django(01):Django简介
    对程序员来说,看透生死远远没有操作0和1那么简单
    一个中年程序员遇到突发情况的一些胡言乱语
    gradle查看项目属性列表
    有道云笔记到简书的迁移工具
    pygame.mixer.Channel--音频通道
    pygame.mixer.Sound音频
    pygame--图像变换
  • 原文地址:https://www.cnblogs.com/jaszzz/p/13040773.html
Copyright © 2020-2023  润新知