zoukankan      html  css  js  c++  java
  • UVA

    /*
      这题的收获 or 技巧 or 注意点 or 说明
      1. getline函数读取整行
      
      2. 流输入stringstream
      
      3. string的size函数、length函数的返回类型都是size_type类型,在使用返回值之前,务必先进行强制类型转换
      
      4. 此题有个坑点,每行的最后一列的单词,后面是没有空行的,直接回车,因此,要将最后一列的输出单独拿出来处理,而其他的就可以一起在循环里输出了
    
      5. 这题可以运用C++输入输出的格式控制,不过也可以不用,直接循环输出也行,solve()1和solve2()函数任意调用一个,都可AC
    */



    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 1005;
    const int maxm = 200;
    vector<string> a[maxn];
    int len[maxm];
    int row, col;
    
    void solve1();
    void solve2();
    
    int main()
    {
    	string s, str;
    	row = col = 0;
    	while (getline(cin, str))
    	{
    		stringstream ss(str);
    		while (ss >> s)
    		{
    			len[col] = max(len[col], (int)s.size());
    			a[row].push_back(s);
    			col++;
    		}
    		row++; col = 0;
    	}
    	
    //	solve1();
    	solve2();
    	
    	return 0;
    }
    
    void solve1()
    {
    	int i, j;
    	cout << setiosflags(ios::left);
    	for (i = 0; i < row; i++)
    	{
    		for (j = 0; j < (int)a[i].size() - 1; j++)
    		cout << setw(len[j] + 1) << a[i][j];
    		
    		cout << a[i][j] << endl;
    	}
    }
    
    void solve2()
    {
    	int i, j, k;
    	for (i = 0; i < row; i++)
    	{
    		for (j = 0; j < (int)a[i].size() - 1; j++)
    		{
    			for ( k = 0; k < (int)a[i][j].size(); k++)
    			cout << a[i][j][k];
    			
    			for (k = 0; k <= len[j] - (int)a[i][j].size(); k++)
    			cout << ' ';
    		}
    		
    		cout << a[i][j] << endl;
    	}
    	
    }


  • 相关阅读:
    [Gym
    [Codeforces995C]Leaving the Bar 瞎搞
    [hdu3685]Rotational Painting 凸包 重心
    [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖
    [hdu4667]Building Fence 计算几何 瞎瘠薄搞
    [hdu3934] 凸包 旋转卡壳
    [Codeforces50C]Happy Farm 5 凸包
    [Codeforces166B]Polygons 凸包
    mex(线段树+离散化)
    CF798D 糖果(思维题)
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789434.html
Copyright © 2011-2022 走看看