UVa1593 Alignment of Code


Alignment of Code

  UVA - 1593 


只给出题目链接;


题意:输入若干代码,要求各列单词的左边界对齐并且尽量靠左。单词之间至少要空一格。

每个单词不超过80字符,每行不超过180字符,一共最多1000行,样例如下:

Sample Input
  
  
start: integer; // begins here stop: integer; // ends here s: string; c: char; // temp
 

Sample Output
  
  
start: integer; // begins here stop: integer; // ends here s: string; c: char; // temp

思路看代码,比较简单。

#include<bits/stdc++.h>
using namespace std;

const int MAX = 1e3+5;
vector<string> w[MAX];
int h[200], line = 0;

int main() {
	string s, s1;
	while(getline(cin,s)) {
		int cnt = 1;
		line++;
		stringstream ss(s);
		while(ss >> s1) {
			h[cnt] = max(h[cnt], (int)s1.length());
			w[line].push_back(s1);
			cnt++;
		}
	}
	for(int i = 1; i <= line; i++) {
		for(int j = 0; j < w[i].size(); j++) {
			s1 = w[i][j];
			cout << s1;
			if(j!=w[i].size()-1) {
				for(int k = s1.length(); k <= h[j+1]; k++) {
					cout <<' ';
				}
			}
		}
		cout <<endl;
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值