• 【习题5-1 UVA


    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    模拟题,每一列都选最长的那个字符串,然后后面加一个空格就好。 这个作为场宽。 模拟输出就好。

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1000;
    const int M = 200;
    
    string ss;
    vector <string> s[N+10];
    int pre[M],lie[M],start[M];
    
    void out(int len, int used)
    {
    	for (int j = 0; j < len - used; j++) putchar(' ');
    }
    
    int main()
    {
    	//freopen("F:\rush.txt", "r", stdin);
    	int row = 0;
    	while (getline(cin, ss))
    	{
    		stringstream ts(ss);
    		string temp;
    		while (ts >> temp) {
    			s[row].push_back(temp);
    			lie[(int)s[row].size() - 1] = max(lie[(int)s[row].size() - 1], (int)temp.size());
    		}
    		row++;
    	}
    	start[0] = 0;
    	for (int j = 1; j < M && lie[j] != 0; j++) start[j] = start[j-1] + lie[j - 1] + 1;
    	for (int i = 0; i < row; i++)
    	{
    		cout << s[i][0];
    		for (int j = 1; j < (int)s[i].size(); j++)
    		{
    			out(start[j]-start[j-1],(int)s[i][j-1].size());
    			cout << s[i][j];
    		}
    		cout << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    2020年12月2日
    2020年12月1日
    2020年11月30日
    2020年11月29日
    2020年11月28日
    2020年11月27日
    2020年11月26日
    2020年11月25日
    浅谈扩展欧几里得算法
    Hello 2020
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7666962.html
Copyright © 2020-2023  润新知