[HW] OJ记录20题之一
记录 20 之一 OJ
2023-09-14 09:01:04 时间
bool GetMinK(unsigned int uiInputNum, int * pInputArray, unsigned int uiK, int * pOutputArray);
int main()
int uiInputNum, uiK;
while (cin uiInputNum uiK)
int *pInputArray = new int[uiInputNum];
for (int i = 0; i uiInputNum; i++)
cin pInputArray[i];
int *pOutputArray = new int[uiK];
GetMinK(uiInputNum, pInputArray, uiK, pOutputArray);
for (int i = 0; i uiK; i++)
if (i != uiK - 1)
cout pOutputArray[i] " ";
else
cout pOutputArray[i];
cout endl;
delete [] pInputArray;
delete [] pOutputArray;
return 0;
bool GetMinK(unsigned int uiInputNum, int * pInputArray, unsigned int uiK, int * pOutputArray)
for (int i = 0; i uiK; i++)
int k = i;
for (int j = i + 1; j uiInputNum; j++)
if (pInputArray[j] pInputArray[k])
k = j;
if (k != i)
int temp = pInputArray[k];
pInputArray[k] = pInputArray[i];
pInputArray[i] = temp;
for (int i = 0; i uiK; i++)
pOutputArray[i] = pInputArray[i];
return true;
}
if (b[0] == 0 || b[2] == strlen(str) - 1 || b[0] == -1 || b[1] == -1 || b[2] == -1 || b[0] == b[1] || b[1] == b[2] || b[2] == b[3]) return false; return true; }
int n[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; for (int i = 0; i strlen(str); i++) if (str[i] = A str[i] = Z) str[i] = str[i] + 32 + 1; if (str[i] z) str[i] = a; else if (str[i] = a str[i] = z) str[i] = n[str[i] - a] + 0; }
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k); void print(ListNode *head); int main() int n; while (cin n) ListNode *head = new ListNode(-1); ListNode *pre = head; while (n--) int val; cin val; ListNode *cur = new ListNode(val); pre- m_pNext = cur; pre = cur; int k; cin k; ListNode *p = FindKthToTail(head- m_pNext, k); cout p- m_nKey endl; return 0; ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) ListNode *p1 = pListHead; ListNode *p2 = pListHead; while (k--) p1 = p1- m_pNext; while (p1- m_pNext != NULL) p1 = p1- m_pNext; p2 = p2- m_pNext; return p2; }
【每日一题Day103】LC1669合并两个链表 | 模拟 思路:遍历链表找到list1中的第a−1个节点和第b+1个节点,然后将第a−1个节点指向list2链表的初始节点,list2链表的尾节点指向list1中的第b+1个节点
if (b[0] == 0 || b[2] == strlen(str) - 1 || b[0] == -1 || b[1] == -1 || b[2] == -1 || b[0] == b[1] || b[1] == b[2] || b[2] == b[3]) return false; return true; }
统计其中的大小写字母,空格和数字,按个数从多到少输出,若个数一样则先输出SCII码比较小的。
实际为字符排序。
如果用string str,直接sort(str.begin(), str.end()),需要包含 algorithm ;
小写字母对应为手机键盘对应的数字。明码中的大写字母转成原来的小写字母是通过,先变成小写,然后ASCII码再加1。输入为明码,输出为密码。
int n[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; for (int i = 0; i strlen(str); i++) if (str[i] = A str[i] = Z) str[i] = str[i] + 32 + 1; if (str[i] z) str[i] = a; else if (str[i] = a str[i] = z) str[i] = n[str[i] - a] + 0; }
将单词倒序排列,中间的空格或其他字符都作为分隔符,输出中的分隔符只能有一个空格,不能有其他符号。
输入:
I am a boy
I 4324 /*- - - /-// fdsf
输出:
boy a am I
fdsf I
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k); void print(ListNode *head); int main() int n; while (cin n) ListNode *head = new ListNode(-1); ListNode *pre = head; while (n--) int val; cin val; ListNode *cur = new ListNode(val); pre- m_pNext = cur; pre = cur; int k; cin k; ListNode *p = FindKthToTail(head- m_pNext, k); cout p- m_nKey endl; return 0; ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) ListNode *p1 = pListHead; ListNode *p2 = pListHead; while (k--) p1 = p1- m_pNext; while (p1- m_pNext != NULL) p1 = p1- m_pNext; p2 = p2- m_pNext; return p2; }
【每日一题Day103】LC1669合并两个链表 | 模拟 思路:遍历链表找到list1中的第a−1个节点和第b+1个节点,然后将第a−1个节点指向list2链表的初始节点,list2链表的尾节点指向list1中的第b+1个节点
相关文章
- 关于WireGuard和zerotier 隧道实现异地组网实现的一些记录
- 【错误记录】Flutter 报错 ( Because xx depends on flutter_driver any from sdk which depends on args 1.6.0 )
- MySQL实现PHP记录功能(phpmysql记录)
- MySQL主键语句—精准掌控数据库记录(mysql主键语句)
- 日志查看MSSQL数据库日志记录的方法(查看mssql)
- 触发记录,写入Redis生命必然的完成(触发器写入redis)
- Oracle中删除记录的技巧(oracle中删除记录)
- Redis记录连续签到天数,让奖励更可见(redis 连续签到天数)
- 删除mysql数据库中的重复数据记录
- asp.netgridview实现全选,反选与删除记录的操作代码
- MySQL生产库Insert了2次同样的记录但是主键ID是不一样的问题的分析过程