时长两年半的某 2022-07-11 05:23 采纳率: 70.6%
浏览 74
已结题

能把这段简短代码的时间复杂度算出来吗(过程)

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct pol
{
int no;
int weight;
};
void display_all_task(vector mor)
{
int len;
len= mor.size();
int i;
for (i = 0; i < len-1; i++)
cout << "("<< mor[i].no << "," << mor[i].weight << "),";
cout << "(" << mor[i].no << "," << mor[i].weight << ")"<<endl;
}
bool cmp(pol a, pol b)
{
return a.weight < b.weight;
}
int main()
{int sk;
int taskNumber = 0;
string str;
getline(cin, str);
stringstream room;
room.str(str);

vector<pol> mor;
while (room >> sk)
{
    pol tmp;
    tmp.no = taskNumber++;
    tmp.weight = sk;
    mor.push_back(tmp);
}
display_all_task(mor);
vector<pol> user;
vector<pol> system;
sort(mor.begin(), mor.end(), cmp);
for (int i = 0; i < mor.size(); i++)
{
    if (mor[i].weight < 50)
    {
        system.push_back(mor[i]);
    }
    else if (mor[i].weight >= 50 && mor[i].weight <= 255)
    {
        user.push_back(mor[i]);
    }
}
cout << endl;
int i;
if (system.size() == 0)
   { cout << "none"<<endl;}
else
{
    for (i = 0; i < system.size(); i++)
        cout << system[i].no << " ";
    cout<<endl;
}

if (user.size() == 0)
    cout << "none"<<endl;
else
{
    for (i = 0; i < user.size(); i++)

cout << user[i].no << " ";
cout<<endl;
}

}

展开全部

  • 写回答

2条回答 默认 最新

  • ...404 Not Found 2022-07-11 08:00
    关注

    o(n)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 7月18日
  • 已采纳回答 7月11日
  • 创建了问题 7月11日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部