4
This commit is contained in:
113
main.ipynb
113
main.ipynb
@@ -7,41 +7,96 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "IndexError",
|
||||
"evalue": "list index out of range",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
||||
"\u001b[31mIndexError\u001b[39m Traceback (most recent call last)",
|
||||
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 2\u001b[39m \n\u001b[32m 3\u001b[39m count = []\n\u001b[32m 4\u001b[39m \n\u001b[32m 5\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m num \u001b[38;5;28;01min\u001b[39;00m nums:\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m count[num] += \u001b[32m1\u001b[39m\n\u001b[32m 7\u001b[39m \n\u001b[32m 8\u001b[39m \u001b[38;5;66;03m# 2. Делаем префиксную сумму\u001b[39;00m\n\u001b[32m 9\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;28;01min\u001b[39;00m range(\u001b[32m1\u001b[39m, \u001b[32m101\u001b[39m):\n",
|
||||
"\u001b[31mIndexError\u001b[39m: list index out of range"
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"nums = [8,1,2,2,3,123,43,5,3,1,5,8,3,965,8,546,456,34,12,3]\n",
|
||||
"gifts = [25,64,9,4,100]\n",
|
||||
"k = 4\n",
|
||||
"\n",
|
||||
"count = []\n",
|
||||
"gift_s = sorted(gifts, inv)\n",
|
||||
"\n",
|
||||
"for num in nums:\n",
|
||||
" if num in count:\n",
|
||||
" \n",
|
||||
" count[num] += 1\n",
|
||||
" \n",
|
||||
"for i in range(1, 101):\n",
|
||||
" count[i] += count[i-1]\n",
|
||||
"\n",
|
||||
"result = []\n",
|
||||
"for num in nums:\n",
|
||||
" if num == 0:\n",
|
||||
" result.append(0)\n",
|
||||
" else:\n",
|
||||
" result.append(count[num - 1])\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"print(result)"
|
||||
"for i \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "903924a0",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'abc'"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"words = [\"alice\",\"bob\",\"charlie\"]\n",
|
||||
"\n",
|
||||
"s = \"\".join(i[:1] for i in words)\n",
|
||||
"s"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "63d7c061",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"s = \"l|*e*et|c**o|*de|\"\n",
|
||||
"\n",
|
||||
"is_count = False\n",
|
||||
"n = 0\n",
|
||||
"for i in s:\n",
|
||||
" if i == '|' and is_count == False:\n",
|
||||
" is_count = True\n",
|
||||
" else:\n",
|
||||
" is_count = False\n",
|
||||
"\n",
|
||||
" if i == '*' and is_count:\n",
|
||||
" n += 1\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"print(n)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5dcedb17",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'a'"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@@ -60,7 +115,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.14.2"
|
||||
"version": "3.13.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user