时长两年半的某 2022-07-11 13: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 16:00
    关注

    o(n)

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

报告相同问题?

问题事件

  • 系统已结题 7月19日
  • 已采纳回答 7月11日
  • 创建了问题 7月11日

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助