- map 和 vector一般都是配合一起使用的。
- 注意循环输入的语法,一般就是取余。
- 最后输出的时候要考虑不够8个的情况
#include<bits/stdc++.h>
using namespace std;
string get_file_name(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); //获取filename
if(file.size()> 16) file = file.substr(file.size()-16,16);
return file;// 最终返回这个文件名
}
int main(){
string filepath, length;
map<string, int> m;
//准备开始循环记录
int start_index = 0;
vector<string> record(8,""); // 只需要循环记录八条即可。
while(cin>>filepath>>length){
string file = get_file_name(filepath);
//改变成想要存储的字符串
string key = file+" "+length;
if(m.find(key)==m.end()){// 找不到应该是等于
m[key] = 1;
record[start_index] = key;//绝对不要push_back
start_index = (start_index+1)%8; // index
}else{
m[key]+=1;//增加一次,但又不占据条数
}
}
for(int i = 0; i < 8; i++){
if(record[start_index] != "") // 如果当前数目不够8个。
cout<<record[start_index]<<" "<<m[record[start_index]]<< endl;
start_index = (start_index + 1) % 8;
}
return 0;
}