mirror of https://github.com/cyp0633/homework.git
Update 10-1 File Format 文件排版 & get accepted.
This commit is contained in:
parent
442217d740
commit
5898f75552
|
@ -4,4 +4,6 @@ test.cpp
|
|||
.gitignore
|
||||
*.in
|
||||
*.out
|
||||
*.txt
|
||||
*.txt
|
||||
showdata.py
|
||||
showdata.cpp
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue