poj 3959 Alignment of Code <vector>“字符串”
Description
Input
Output
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 <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <sstream>
using namespace std; vector<string> code[]; //1000行单词
int len[];
int main()
{
int n = ; //len中存储一行中每个单词的长度
string line;
while((getline(cin,line)) != NULL){ n++;
stringstream ss(line); //不用这个会累死的 int q = ; //q为每行单词第几个数
string word;
while(ss >> word){
int t = word.length();
if(n == )len[q] = t;
else if(len[q] < t)len[q] = t; //同一列单词中最长的
q++;
code[n].push_back(word);
}
} for(int i = ;i <= n;i++){ int N = code[i].size(); for(int j = ;j < N;j++){ line = code[i][j];
int q = line.length();
cout << code[i][j]; for( int p = ;p <= len[j] - q;p++)printf(" ");
}
putchar('\n');
} // system("pause");
return ;
}
n++的位置不对 导致插入向量的字符串存在问题
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <sstream>
using namespace std; vector<string> code[]; //1000行单词
int len[];
int main()
{
int n = ; //len中存储一行中每个单词的长度
string line;
while((getline(cin,line)) != NULL){
stringstream ss(line); //不用这个会累死的 int q = ; //q为每行单词第几个数
string word;
while(ss >> word){
int t = word.length();
if(n == )len[q] = t;
else if(len[q] < t)len[q] = t; //同一列单词中最长的
q++;
code[n].push_back(word);
}
n++;
}
for(int i = ;i < n;i++){ int N = code[i].size(); for(int j = ;j < N;j++){ line = code[i][j];
int q = line.length();
cout << code[i][j]; for( int p = ;p <= len[j] - q;p++)printf(" ");
}
putchar('\n');
} // system("pause");
return ;
}
补充几点
在vector中查找特定的元素
用 find 函数,头文件#include <algorithm>
vector<int> x;
x.push_back();
x.push_back();
x.push_back();
vector<int>::iterator iter;
iter = find(x.begin(), x.end(), );
清空vector
vector<int>student;
student.clear();
poj 3959 Alignment of Code <vector>“字符串”的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 5-1/UVa1593 - Alignment of Code
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1593 - Alignment of Code #include&l ...
- UVA 1593 Alignment of Code(紫书习题5-1 字符串流)
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...
- POJ 1836 Alignment
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...
- POJ 3174 Alignment of the Planets (暴力求解)
题意:给定 n 个坐标,问你三个共线的有多少组. 析:这个题真是坑啊,写着 n <= 770,那么一秒时间,三个循环肯定超时啊,我一直不敢写了,换了好几种方法都WA了,也不知道为什么,在比赛时坑 ...
- POJ 1208 The Blocks Problem --vector
http://poj.org/problem?id=1208 晚点仔细看 https://blog.csdn.net/yxz8102/article/details/53098575 #include ...
- poj 3415 后缀数组 两个字符串中长度不小于 k 的公共子串的个数
Common Substrings Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 11469 Accepted: 379 ...
- poj 2774 后缀数组 两个字符串的最长公共子串
Long Long Message Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 31904 Accepted: 12 ...
- POJ 1836 Alignment (双向DP)
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10804 Accepted: 3464 Descri ...
- 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)
题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...
随机推荐
- system进程启动普通用户进程调研
system进程启动普通用户进程 关键函数是CreateProcessAsUser 主要思路是先取得目的用户的token,然后用上面的函数启动 1.从explorer中取token BOOL GetT ...
- VC连接数据库方式
转自:http://www.cnblogs.com/renyuan/archive/2012/07/27/2612412.html 目前Windows系统上常见的数据库接口包括: ODBC(开放数据库 ...
- Web项目中用模板Jsp页面引入所有静态样式脚本文件(js,css等)
这样的好处是不需要再每个页面中都添加太多的外链接(不会减少请求数量),但对开发会更快捷,如果更改这些文件的位置或名称,只需要更改模板文件,不需要一个一个页面复制粘贴:同时可以为不同jsp页面组创建不同 ...
- Fun with dynamicobject dynamic and the settings table
What came before In my previous post I discussed ways of making the settings table using Generics to ...
- 一键分享到新浪微博、腾讯微博、搜狐微博、人人网、开心网、百度收藏等js代码大全
下面给大家一些分享的js代码,只要把代码插入自己的网页中稍微修改一下图片路径就可以用了,好了,废话少说,上代码: document.writeln("<b>喜欢本文,那就分享到 ...
- CSS定义网页滚动条
(一)滚动条样式主要涉及到如下CSS属性: overflow属性: 检索或设置当对象的内容超过其指定高度及宽度时如何显示内容overflow: auto; 在需要时内容会自动添加滚动条overflow ...
- Python之路第二天,基础(2)-基本数据类型
一.Python数据类型 数 在Python中有4种类型的数,整数,长整数,浮点数和复数. 2是一个整数的例子 长整数不过是大一点的整数 3.23和52.3E是浮点数的例子.E标记表示10的幂.52. ...
- python Cmd实例之网络爬虫应用
python Cmd实例之网络爬虫应用 标签(空格分隔): python Cmd 爬虫 废话少说,直接上代码 # encoding=utf-8 import os import multiproces ...
- 1169 二叉树遍历(XCOJ DFS)
给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度≤8). 样例输入 BADC BDCA 样例输出 ABCD #include <iostream> ...
- 最大子数组分治方案C++实现
大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下实现最大子数组的分治策略,算法来自<算法导论> #include<iostr ...