略懂c语言 2022-04-22 21:28 采纳率: 92.6%
浏览 27
已结题

不知道简便方法行不行,老是超时

可以简化版吗,太长了输出需要一样
http://t.csdn.cn/rYYlr
我的代码如下
#include
#include
#include
#include using std::cin;using std::cout;using std::vector;using std::string;using std::find;class Solution{public: static vector tags(vector inputs){ vector tag; for(string x:inputs){ if(x[0]=='#'&&x.size()>1&&x.find('#',1)==x.npos){ tag.push_back(x); } } return tag; } static int tag_num(vectortag){ int num=0; int flag=0; for(string x:tag){ if(count(tag.begin()+flag, tag.end(), x)<=1){ num++; } flag++; } return num; } static int single(string x,vectortag){ int num=0; for(string y:tag){ if(x.compare(y)==0){ num++; } } return num; }};int main(int argc, char const *argv[]){ string str; vector orn; while(cin>>str){ orn.push_back(str); } vector tags(Solution::tags(orn)); cout<<Solution::tag_num(tags)<<std::endl; vector tags_new(tags); //sort( tags_new.begin(), tags_new.end() ); tags_new.erase( unique( tags_new.begin(), tags_new.end() ), tags_new.end() ); for(auto x:tags_new){ cout<<x<<" "<<Solution::single(x,tags)<<std::endl; } return 0;}

  • 写回答

1条回答 默认 最新

  • 浪客 2022-04-23 09:38
    关注

    做一下排版,编辑器有代码块。
    这样的基本没人看。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月1日
  • 已采纳回答 4月23日
  • 创建了问题 4月22日

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序