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 ...
随机推荐
- jQuery封装的表单验证,模仿网易或者腾讯登录的风格
模仿网易邮箱做了一个登录表单验证,不太好,请指教 上代码 <form action="" name="" id="form1"> ...
- css3实现各种渐变效果,比较适合做手机触屏版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- The Time in Words
def main(): time = ["one", "two", "three", "four", "fiv ...
- ACM ICPC Team
Link: https://www.hackerrank.com/challenges/acm-icpc-team/submissions/code/11617807 def count_max_to ...
- HTML布局总结
网页的三大元素结构(内容html标签)+表现(布局CSS)+行为(js) CSS选择器1.标记选择器2.类别选择器(.red)3.ID选择器(#name)4.复合选择器(交集选择器 标记选择器+类别 ...
- Django的 select_related 和 prefetch_related 函数对 QuerySet 查询的优化(三)
4.一些实例 如果我们想要获得所有家乡是湖北的人,最无脑的做法是先获得湖北省,再获得湖北的所有城市,最后获得故乡是这个城市的人.就像这样: 1 2 3 4 5 >>> hb = Pr ...
- meta 属性
几乎所有的网页里,我们可以看到类似下面这段的html代码:<head><meta http-equiv="content-Type" content=" ...
- 开心菜鸟系列----变量的解读(javascript入门篇)
console.info( console.info(window['weiwu']) console.info(window. ...
- (转)C#在父窗口中调用子窗口的过程(无法访问已释放的对象)
C#在父窗口中调用子窗口的过程: 1. 创建子窗口对象 2. 显示子窗口对象 笔者的程序中,主窗体MainFrm通过菜单调用子窗口ChildFrm.在窗体中定义了子窗口对象,然后在菜单项点击事件中 ...
- 重启电脑提示Error:no such partition grub rescue
我的系统是Win7,在使用Ubuntu12.04自带的Wubi.exe安装双系统时,系统提示重新启动计算机,重启后电脑就停留在了黑屏界面并提示: error:no such partition gru ...