3道題,2小時。
題目1
不一樣的排序:https://code.mi.com/problem/list/view?id=128&cid=11
一般
我的題解
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int yinzi(int x)
{
int count = 0;
int temp = (int)sqrt(x);
for(int i = 1; i <= temp; i++)
{
if(x % i == 0)
count++;
}
return count+1;
}
void sortA(int a[][2], int n)
{
bool sorted = false;
while(!sorted)
{
sorted = true;
for(int i = 0; i < n-1; i++)
{
if(a[i][1] > a[i+1][1])
{
swap(a[i][1], a[i+1][1]);
swap(a[i][0], a[i+1][0]);
sorted = false;
}
}
n--;
}
}
int main()
{
// please write your code here
int k, n;
cin >> k >> n;
int a[n][2] = {0};
for(int i = 0; i < n; i++)
cin >> a[i][0];
for(int i = 0; i < n; i++)
{
a[i][1] = yinzi(a[i][0]);
}
sortA(a, n);
cout << a[k-1][0] << endl;
return 0;
}
結果:超時。