zoukankan      html  css  js  c++  java
  • Uva



    直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐。

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cctype>
    #include <cstring>
    #include <string>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <iomanip> 
    
    using namespace std;
    
    vector<string> s[1005];
    int len[185];
    
    int main()
    {
    	string line, buf;
    	int i = 0, j = 0;
    	while (getline(cin, line)) {
    		istringstream stream(line);
    		while (stream >> buf) {
    			len[j] = max(len[j], (int)buf.length());
    			j++;
    			s[i].push_back(buf);
    		}
    		i++;
    		j = 0;
    	}
    	// 设置左对齐
    	cout << setiosflags(ios::left);
    	for (int k = 0; k < i; k++) {
    		int l = 0;
    		for (l; l < s[k].size() - 1; l++) {
    			// setw设置宽度
    			cout << setw(len[l] + 1) << s[k][l];
    		}
    		cout << s[k][l] << endl;
    	}
    
    	return 0;
    }





  • 相关阅读:
    ajax post 时 form数据serialize()
    dapper 自定义数据库字段和代码中Model字段不一致时候的mapping方法
    TImage 的一些操作
    AOP
    SSL、数字签名、CA 工作原理
    RESTFUL
    tomcat
    Hibernate
    设计模式
    Spring配置
  • 原文地址:https://www.cnblogs.com/zhangyaoqi/p/4591591.html
Copyright © 2011-2022 走看看