题解 | #简单错误记录#

简单错误记录

https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb

string_all = {};
num = 1;
try
    while 1
        line = input('', 's');
        string_all{num} = line;
        num = num + 1;
    end
catch
end

path = {};
for jj = 1 : num -1
  str_div = strsplit(string_all{jj},'\');
  str_div_2 = strsplit(str_div{end},' ');
  path_now = char(str_div_2{1});
  if length(path_now) <=16
    path{jj} = path_now;
  else
    path{jj} = path_now(end-15:end);
  end
  num_hang(jj) = str2num(str_div_2{2});
end

cal = [];
num_1 = 1;
for kk = 1 : num - 2
   path_1 = char(path{kk});
   for kk1 = kk+1 : num -1
      path_2 = char(path{kk1});
      if strcmp(path_1, path_2) && num_hang(kk) == num_hang(kk1);
         cal(num_1,:) = [kk,kk1];
         num_1 = num_1 + 1;
      end
   end
end

out_end = {};
out_num = ones(num-1,1);
for kk = 1 : size(cal,1)
    out_num(cal(kk,1)) = out_num(cal(kk,1)) + 1;
    out_num(cal(kk,2)) = 0;
end

[ind] = find(out_num ~= 0);
if length(ind) <= 8
   for kk1 = 1 : length(ind)
      printf("%s %s %s\n", path{ind(kk1)}, num2str(num_hang(ind(kk1))), num2str(out_num(ind(kk1))));
   end
else
   for kk1 = length(ind)-7 : length(ind)
       printf("%s %s %s\n", path{ind(kk1)}, num2str(num_hang(ind(kk1))), num2str(out_num(ind(kk1))));
   end
end

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务