parent
b57d1b85a6
commit
ccc02af3c2
@ -0,0 +1,90 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
class directory{
|
||||
vector<string> files;
|
||||
int N;
|
||||
public:
|
||||
directory() {}
|
||||
~directory() {}
|
||||
void add_file(string f) {
|
||||
files.push_back(f);
|
||||
}
|
||||
void copy_file(string name,int n=1) {
|
||||
// check exist
|
||||
bool flag = false;
|
||||
for(string j : files) {
|
||||
if (name == j) flag = true;
|
||||
}
|
||||
if (!flag) {
|
||||
cout<<"error"<<endl;
|
||||
return;
|
||||
}
|
||||
|
||||
string back = name;
|
||||
int index = name.rfind('.',name.size());
|
||||
if(index == -1) {
|
||||
for(int i = 1;i <= n;i++){
|
||||
back = name;
|
||||
back.append('_' + to_string(i));
|
||||
bool flag = false;
|
||||
for(string j : files) {
|
||||
if (back == j) flag = true;
|
||||
}
|
||||
if (flag) {
|
||||
n++;
|
||||
continue;
|
||||
}
|
||||
cout<<back<<' ';
|
||||
add_file(back);
|
||||
}
|
||||
} else {
|
||||
for(int i = 1;i <= n;i++){
|
||||
back = name;
|
||||
back.replace(index,1,'_' + to_string(i) + '.');
|
||||
bool flag = false;
|
||||
for(string j : files) {
|
||||
if (back == j) flag = true;
|
||||
}
|
||||
if (flag) {
|
||||
n++;
|
||||
continue;
|
||||
}
|
||||
cout<<back<<' ';
|
||||
add_file(back);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
directory dir;
|
||||
for(int i=0;i<2;i++){
|
||||
string temp,cmd;
|
||||
vector<string> part;
|
||||
getline(cin,cmd);
|
||||
stringstream ss(cmd);
|
||||
while (ss>>temp) {
|
||||
part.push_back(temp);
|
||||
}
|
||||
if (part[0] == "copy" && part.size() == 3) {
|
||||
dir.copy_file(part[1],stoi(part[2]));
|
||||
cout<<endl;
|
||||
}
|
||||
else if(part[0] == "copy") {
|
||||
dir.copy_file(part[1],1);
|
||||
cout<<endl;
|
||||
}
|
||||
else {
|
||||
for(string j: part) {
|
||||
dir.add_file(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue