简介
恶心
4、循环记录时,只以第一次出现的顺序为准,后面重复的不会更新它的出现时间,仍以第一次为准.
浪费爷爷的时间.
明明只有8个空间, 却按照从头开始查找.
code
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
struct Error{
string in;
int line;
int time;
};
string decomp(string filepath){
int end_pos = filepath.size()-1;
for(; end_pos >= 0; end_pos--){
if(filepath[end_pos] == '\') break;
}
string file = filepath.substr(end_pos + 1, filepath.size() - end_pos - 1);
if(file.size() > 16) file = file.substr(file.size()-16, 16);
return file;
}
void dec(string in, string &out, int &line) {
for(int i=0; i<in.size(); i++) {
if(in[i] == ' ') {
for(int j=i-1; j>=0; j--){
if(in[j] == '\') break;
if(out.size() >= 16) break;
out += in[j];
}
reverse(out.begin(), out.end());
stringstream ss;
string num = in.substr(i+1);
ss << num;
ss >> line;
return;
}
}
return;
}
int main() {
string in;
vector<Error> v(8, {"", -1, 1});
string filepath; int length;
int index = 0;
while(cin >> filepath >> length) {
string file = decomp(filepath);
string s = file;
int line = length;
bool check = false;
for(int i=0; i<8; i++){
if(v[i].in == s && v[i].line == line){
v[i].time++;
check = true;
break;
}
}
if(check) {
continue;
}else{
v[index].in = s;
v[index].line = line;
v[index].time = 1;
index++;
index = index % 8;
}
}
for(int i = index; i < 8; i++){
if(v[i].line != -1)
cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
}
for(int i = 0; i < index; i++){
cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
}
return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <set>
using namespace std;
struct Error{
string in;
int line;
int time;
};
string decomp(string filepath){
int end_pos = filepath.size()-1;
for(; end_pos >= 0; end_pos--){
if(filepath[end_pos] == '\') break;
}
string file = filepath.substr(end_pos + 1, filepath.size() - end_pos - 1);
if(file.size() > 16) file = file.substr(file.size()-16, 16);
return file;
}
void dec(string in, string &out, int &line) {
for(int i=0; i<in.size(); i++) {
if(in[i] == ' ') {
for(int j=i-1; j>=0; j--){
if(in[j] == '\') break;
if(out.size() >= 16) break;
out += in[j];
}
reverse(out.begin(), out.end());
stringstream ss;
string num = in.substr(i+1);
ss << num;
ss >> line;
return;
}
}
return;
}
int main() {
string in;
vector<Error> v(8, {"", -1, 1});
string filepath; int length;
set<string> dis;
int index = 0;
while(cin >> filepath >> length) {
string file = decomp(filepath);
string s = file;
int line = length;
bool check = false;
for(int i=0; i<8; i++){
if(v[i].in == s && v[i].line == line){
v[i].time++;
check = true;
break;
}
}
if(check) {
continue;
}else{
if(dis.find(file + " " + to_string(line)) != dis.end()) {
continue;
}
v[index].in = s;
v[index].line = line;
v[index].time = 1;
index++;
index = index % 8;
}
dis.insert(file + " " + to_string(line));
}
for(int i = index; i < 8; i++){
if(v[i].line != -1)
cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
}
for(int i = 0; i < index; i++){
cout << v[i].in << " " << v[i].line << " " << v[i].time << std::endl;
}
return 0;
}