Update 10-1 File Format 文件排版 & get accepted.

This commit is contained in:
cyp0633 2020-12-23 23:12:39 +08:00
parent 442217d740
commit 5898f75552
3 changed files with 38 additions and 16 deletions

4
.gitignore vendored
View File

@ -4,4 +4,6 @@ test.cpp
.gitignore
*.in
*.out
*.txt
*.txt
showdata.py
showdata.cpp

View File

@ -1,40 +1,56 @@
//文件排版(文本文件读写)
#include<cstdio>
#include<string>
#include<iostream>
#include<iomanip>
#include<sstream>
#include <cstdio>
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;
int main() {
int main()
{
int commaPos;
string::size_type colonPos;
string tmp;
string postList, castList;
scanf("%d\n", &commaPos);
freopen("listin.txt", "r", stdin);
freopen("listout.txt", "w", stdout);
while (getline(cin, tmp)) {
while (getline(cin, tmp))
{
stringstream ss;
postList = "";
castList = "";
ss.str(tmp);
while (ss >> tmp) {
if (tmp == ":") {
while (ss >> tmp)
{
if (tmp == ":")
{
break;
}
if (tmp[tmp.length() - 1] == ':') {
tmp.pop_back();
postList += tmp + ' ';
colonPos = tmp.find(':');
if (colonPos != string::npos)
{
if (colonPos != 0)
{
postList += tmp.substr(0, colonPos) + ' ';
}
if (colonPos + 1 != tmp.length())
{
castList += tmp.substr(colonPos + 1, tmp.length()) + ' ';
}
break;
} else {
}
else
{
postList += tmp + ' ';
}
}
while (ss >> tmp) {
while (ss >> tmp)
{
castList += tmp + ' ';
}
cout << setw(commaPos) << left << postList << ": " << castList << '\n';
cout << setw(commaPos - 1) << left << postList << ": " << castList << '\n';
}
fclose(stdout);
fclose(stdin);

View File

@ -5,10 +5,14 @@ using namespace std;
int main()
{
//freopen("listin.txt","r",stdin);
//freopen("listout.txt","w",stdout);
string a;
while(getline(cin,a))
{
cout<<a<<'\n';
}
//fclose(stdin);
//fclose(stdout);
return 0;
}