/*
情报破译
我方截获敌方一份文档execute.stdin,发现敌方为了防止泄密,句子单词顺序被翻转了。
例如,“office. post the attack morning, tomorrow Act”,原文应该是“Act tomorrow morning, attack the post office.”
组织需要你的时候到了,请你用程序把文档破译出来。
*/
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
ifstream ifs("execute.stdin");
char cVal;
vector<char> vecSubChar;
vector<vector<char>> vecChar;
int i = 0, j = 0, NewlineFlag = 0, Cnt = 0;
while (ifs.get(cVal)) // 这里不能用ifs >> cVal ,>> 标准输入流会漏掉' '
{
if (cVal != ' ' && cVal != '\n')
vecSubChar.push_back(cVal);
if (cVal == ' ' || cVal == '\n')
{
++i;
vecChar.push_back(vecSubChar);
vecSubChar.clear();
}
if (cVal == '\n')
NewlineFlag = i;
}
ifs.close();
vecChar.push_back(vecSubChar);
Cnt = i + 1;
for (i = 0; i < NewlineFlag/2; ++i)
{
vecSubChar.clear();
vecSubChar = vecChar[NewlineFlag-1 - i];
vecChar[Newline
【C++】联发科初赛第二题《情报破译》
最新推荐文章于 2025-02-08 17:19:16 发布