完全对齐使用向量 [英] Full Justify using vectors

查看:101
本文介绍了完全对齐使用向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试创建一个证明文件内容合理性的程序。到目前为止我的代码是这样的:

Hello, I am trying to create a program that justifies the contents of the file. so far my code is this:

#include <iostream>
#include <vector>
#include<string>
#include <fstream>
using namespace std;

int main()
{
int column=25;
vector<string>paragraph;
vector<string>words;
string str;

  ifstream fin("myFile.txt");

  do{
    str="";
    getline(fin,str);
    paragraph.push_back(str);
  }while(str!="");
fin.close();
words.push_back(paragraph.at(0));
for(int i=0;i<words.size();i++){

    str=words.at(i);

}

for(int i=0;i<column;i++){

    cout<<str.at(i);

    sum+=sum;



}



我把文件的所有内容在矢量段落中。和矢量字上的每一行。我要在每一行显示25个字符。这之后会有什么步骤?谢谢你的帮助


I put all the contents of the file in the vector paragraph. and each line on vector words. Ihave to display 25 characters on each line. what should be steps after this? Thank you for your help

推荐答案

yikes ..谈谈桥下长长的水..嗯嗯



iirc,你需要做类似的事情(这是非常粗糙的)



a)将句子中的字符数设置为0

b)循环通过单词列表

c)如果单词长度+句子中的字符数> 25,[输出句子]

d)为这个句子列表添加单词

e)在句子中添加单词长度

f)结束循环

g)输出单词列表中剩余的剩余单词



[输出句子]

简单地说,你: -

计算你需要多少空格的数量,即25个 - 句子中的字符

循环通过这个句子列表的单词

输出用空格和'额外'空格分隔的单词

清除这个句子列表中的单词

将句子中的字符数设置为0

end循环



问题是输出由空格和'额外'空格分隔的单词 - 你需要平衡空间的位置,所以你最终不会所有在句子的左侧或右侧
yikes .. talk about water long under the bridge .. hmmm

iirc, you need to do something like (and this is very rough)

a) set count of characters in sentence to 0
b) loop through the list of words
c) if word length + count of characters in sentence > 25, [output sentence]
d) add word to words for this sentence list
e) add word length to count of characters in sentence
f) end loop
g) output any remaining word left in words list

[output sentence]
simplistically, you :-
calculate the number of extra spaces you need ie 25 - characters in sentence
loop through the words for this sentence list
output the words separated by spaces and 'extra' spaces
clear the words for this sentence list
set the count of characters in sentence to 0
end loop

The trouble is "output the words separated by spaces and 'extra' spaces" - you need to balance where the spaces go, so you don't end up with all on the left or right side of the sentence


这篇关于完全对齐使用向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆