关于OJ1028的参考解法】的更多相关文章

其中运用了最小公倍数与最大公约数乘积等于两数相乘的定理. #include <stdio.h> int main(int argc, char *argv[]) { int a,b,c,d,e; scanf("%d %d",&a,&b); d=a*b; ) { c=a%b; a=b; b=c; } e=d/a; printf("%d\n",e); ; }…
#include <stdio.h> int main(int argc, char *argv[]) { int a,b,c; scanf("%d %d",&a,&b); ) { c=a%b; a=b; b=c; } printf("%d\n",a); ; }…
第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最后也只过了A.B.D3题,但能上分还是非常的激动不已呀. 先发出来A.B.D的参考解法,C比赛时读了题感觉自己可以做出来,但时间只剩20分钟了,索性弃疗--. 11.23 补充上了C的参考代码 A题: 题目地址 用一些str函数应该也可以做,但考虑到字符串长度只有不到100以及题目整体不是很复杂,不…
一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ For example, given the above Employee table, the nth hig…
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has…
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will autom…
Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the or…
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: 输入: [1,2,3] 输出: [1,2,4] 解释: 输入数组表示数字 123. 示例 2: 输入: [4,3,2,1] 输出: [4,3,2,2] 解释: 输入数组表示数字 4321. 我的错误解法:不能转为数字然后操作,算法正确但是会越界然后得不到正确结果 public static int[]…
(1 pass) 以 Unix 风格给出一个文件的绝对路径,你需要简化它.或者换句话说,将其转换为规范路径. 在 Unix 风格的文件系统中,一个点(.)表示当前目录本身:此外,两个点 (..) 表示将目录切换到上一级(指向父目录):两者都可以是复杂相对路径的组成部分.更多信息请参阅:Linux / Unix中的绝对路径 vs 相对路径 请注意,返回的规范路径必须始终以斜杠 / 开头,并且两个目录名之间必须只有一个斜杠 /.最后一个目录名(如果存在)不能以 / 结尾.此外,规范路径必须是表示绝对…
给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 1: 输入: [   [1,1,1],   [1,0,1],   [1,1,1] ] 输出: [   [1,0,1],   [0,0,0],   [1,0,1] ] 示例 2: 输入: [   [0,1,2,0],   [3,4,5,2],   [1,3,1,5] ] 输出: [   [0,0,0,0],   [0,4,5,0],   [0,3,1,0] ] 进阶: 一个直接的解决方案…