至少这些问题:
错误的分配大小 @Weather Vane
避免分配错误。分配给被告的对象的大小,而不是类型。
// t=(emp*)malloc(n*sizeof(int));
t = malloc(sizeof t[0] * n);
更容易正确编码,审查和维护。
非原始化p
@craig estey
f(p =='y')
是未定义的行为,因为p
是非初始化的。
这暗示OP并未启用所有警告。节省时间 - 启用所有警告。
emp
未定义
也许OP不是使用C编译器,而是使用C ++?
i
未在中定义的(i = 0; i< n; i ++){
is int> int i;
真正的代码?
坏“%s”
没有 width ,“%s”
比get> gets()差
。使用宽度喜欢“%49S”
。
假设结果需要为[[1,2,3,4],[5,6,7,8],[9,10]]
您可以使用Array.Reduce:
const items = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
const parts = 3
const wordsPerLine = Math.ceil(items.length / parts)
const result = items.reduce((resultArray, item, index) => {
const arrayIndex = Math.floor(index / wordsPerLine)
if (!resultArray[arrayIndex]) {
resultArray[arrayIndex] = [] // start a new array
}
resultArray[arrayIndex].push(item)
return resultArray
}, [])
// result => [[ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10 ]]
是的,您只能使用宏只能做到这一点:
macro_rules! compose {
($($rest:ident),+) => {
|x| { compose!(expand x, $($rest),*) }
};
(expand $inner:expr, $function:ident, $($rest:ident),*) => {
compose!(expand $function($inner), $($rest),*)
};
(expand $inner:expr, $function:ident) => {
$function($inner)
};
}
let a = compose!(f, g, h, i);
//expands into:
let a = |x| i(h(g(f(x))));
这是延续方法的另一个好候选人。讨论是在链接上的,但我将使用c
进行以下操作,以控制方程的更非线性术语:
import sympy as sym
x,y = sym.symbols('x,y')
dmin = 70 #minimum of the actuator
dmax = 140 #maximum of the actuator
l3 = 10
l4 = 10
Amin = 0.523599 #min angle in radians
Amax = 2.0944 #max angle in radians
for c in range(10):
c=c/S(10)
cos1 = sym.cos(Amin - sym.atan(l4/x)*c - sym.atan(l3/y)*c)
cos2 = sym.cos(Amax - sym.atan(l4/x)*c - sym.atan(l3/y)*c)
a2 = x**2 + l4**2
b2 = y**2 + l3**2
f=sym.Eq(a2 + b2 - 2*sym.sqrt(a2)*sym.sqrt(b2)*cos1, dmin**2)
g=sym.Eq(a2 + b2 - 2*sym.sqrt(a2)*sym.sqrt(b2)*cos2, dmax**2)
if not c:
gs = solve((f,g),(x,y),dict=False)
else:
sol = []
for gi in gs:
sol.append(nsolve((f,g),(x,y),gi))
gs
[(-107.967591836877, -48.6044884662980),
(-107.967591836877, 48.6044884662980),
(-48.6044884662980, -107.967591836877),
(-48.6044884662980, 107.967591836877),
(48.6044884662980, -107.967591836877),
(48.6044884662980, 107.967591836877),
(107.967591836877, -48.6044884662980),
(107.967591836877, 48.6044884662980)]
' c
转到1成为最终解决方案
>>> for i in ordered(sol):tuple(i)
...
(-111.790176548536, 48.5400429865187)
(-96.2635727943765, -52.7612279529407)
(-52.7612279529407, -96.2635727943765)
(-49.3470005072566, 104.216202951134)
(48.5400429865187, -111.790176548536)
(49.8069789979713, 117.241028072945)
(104.216202951134, -49.3470005072566)
(117.241028072945, 49.8069789979713)
In [11]: arr = np.array([[1,0],[2,3]])
In [12]: id(arr)
Out[12]: 1915221691344
In [13]: M = sparse.csr_matrix(arr)
In [14]: id(M)
Out[14]: 1915221319840
In [15]: arr += arr
In [16]: id(arr)
Out[16]: 1915221691344
+=
用于数组的就位。
In [17]: M += M
In [18]: id(M)
Out[18]: 1915221323200
对于稀疏矩阵,它会创建一个新的稀疏矩阵对象。它不会在现场修改矩阵。
对于此操作,可以将数据
属性修改到位:
In [20]: M.data
Out[20]: array([2, 4, 6], dtype=int32)
In [21]: M.data += M.data
In [22]: M.A
Out[22]:
array([[ 4, 0],
[ 8, 12]], dtype=int32)
但是通常,在稀疏矩阵中添加一些东西可以修改其稀疏性。稀疏的开发人员以智慧决定了不可能的,或者只是不成本效益(编程或运行时间?),而无需创建新的矩阵。
虽然在np.matrix
子类上构图稀疏矩阵,但它不是ndarray
的子类,并且没有义务以完全相同的方式行事。
In [30]: type(M).__mro__
Out[30]:
(scipy.sparse.csr.csr_matrix,
scipy.sparse.compressed._cs_matrix,
scipy.sparse.data._data_matrix,
scipy.sparse.base.spmatrix,
scipy.sparse.data._minmax_mixin,
scipy.sparse._index.IndexMixin,
object)
您可以使用联合所有
以简单的方式获得玩家的分数。然后,您可以订购分数并使用limit
以最大分数获取行:
WITH scores AS
(
SELECT pontuacao_jog1 AS score, data_jogo
FROM partidas
WHERE id_jogador1 = 'CR7'
UNION ALL
SELECT pontuacao_jog2 AS score, data_jogo
FROM partidas
WHERE id_jogador2 = 'CR7'
)
SELECT *
FROM scores
ORDER BY score DESC
LIMIT 1;
唯一问题:如果有两天的最高分数相同,则只会显示其中一个任意选择。如果您想显示这两者:
WITH scores AS ( <same as above> )
SELECT *
FROM scores
WHERE score = (SELECT MAX(score) FROM scores);
这是编写CTE的另一种方法(aka 使用
子句):
WITH scores AS
(
SELECT
CASE WHEN id_jogador1 = 'CR7'
THEN pontuacao_jog1
ELSE pontuacao_jog2
END AS score,
data_jogo
FROM partidas
WHERE (id_jogador1 = 'CR7' OR id_jogador2 = 'CR7')
)
首先,尝试获取最新的Chrome驱动程序,并检查是否解决了问题。
就我而言,它没有解决这个问题。但是,到目前为止,以下解决方案对我有用。以下是C#代码,但您可以使用特定语言遵循相同的逻辑。我们在这里做的是,
步骤1:使用硒操作对象专注于元素,
步骤2:然后单击元素
步骤3:如果有例外,那么我们在元素上触发javascript“ click”事件。通过Selenium浏览器驱动程序的“ ExecuteCript”方法执行JavaScript脚本。
您也可以跳过步骤1和2,也只尝试步骤3。步骤3会独自工作,但在一种情况下,我注意到某个方案中的某些奇怪行为,即使它成功单击了该元素,但在单击元素后仍会在我的代码其他部分中引起意外的行为。
try
{
//Setup the driver and navigate to the web page...
var driver = new ChromeDriver("folder path to the Chrome driver");
driver.Navigate().GoToUrl("UrlToThePage");
//Find the element...
var element = driver.FindElement(By.Id("elementHtmlId"));
//Step 1
new Actions(driver).MoveToElement(element).Perform();
//Step 2
element.Click();
}
catch (Exception)
{
//Step 3
driver.ExecuteScript("document.getElementById('elementHtmlId').click();");
}
您的最后一个选择是要走的方法(错字除外):
MyType Reversed2(MyType value)
{
Reverse(value);
return value;
}
[n] RVO不适用于返回结果;
,但至少它是隐式移动的,而不是复制的。
您要么根据参数的值类别,要么有一个副本 + a动作或两步。
我知道这是一个旧的线程,但是今天我写了以下问题(混合上面的答案以及更多内容),这是一个明确的解决方案:
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
# Ignore if change from voice channels not from bot
if not member.id == self.bot.user.id:
return
# Ignore if change from voice channels was triggered by disconnect()
elif before.channel is not None:
return
# Check if playing when in voice channel, every 180 seconds
else:
voice = after.channel.guild.voice_client
while True:
await asyncio.sleep(180)
# If not playing, disconnect
if voice.is_playing() == False:
await voice.disconnect()
break
没有这样的功能可以隐藏多行的一部分。我们只能在列中显示或隐藏整个项目。 SharePoint将显示前5行,并将其隐藏为默认情况。
请尝试以下操作:
constructor(
private router: Router
) {
router.events.pipe(
filter(event => event instanceof NavigationStart)
).subscribe((event: NavigationStart) => {
// You only receive NavigationStart events
console.log(event.url);
});
}
对于严格的模式,您可以尝试以下操作:
constructor(
private router: Router
) {
router.events.pipe(
filter((event): event is NavigationEnd => event instanceof NavigationStart)
).subscribe((event: NavigationStart) => {
// You only receive NavigationStart events
console.log(event.url);
});
}
Spring automatically calls quit()
on your injected driver
public class MyChromeDriver extends ChromeDriver
{
private static final String SCREENSHOT_DIR = "/path/for/screenshots/";
public void takeScreenshot(String fileName) throws IOException
{
File srcfile = getScreenshotAs(OutputType.FILE);
File dstFile = new File(SCREENSHOT_DIR + fileName + ".png");
dstFile.getParentFile().mkdirs();
FileCopyUtils.copy(srcfile, dstFile);
}
/**
* No-op quit which Spring can call after each test w/o doing any damage
* @deprecated use {@link #realQuit()}
*/
@Override
@Deprecated
public void quit() {}
/**
* Call this to actually invoke {@link ChromeDriver#quit()}
*/
public void realQuit()
{
super.quit();
}
}
这使我能够使我的基础测试类能够在错误时拍摄屏幕截图。
@ExtendWith(SeleniumMvcIntegrationTest.class)
public class SeleniumMvcIntegrationTest implements TestWatcher
{
@Inject
protected MyChromeDriver driver;
@Override
public void testFailed(ExtensionContext context, Throwable throwable)
{
getTestInstanceDriver(context).takeScreenshot(throwable.getClass().getSimpleName() + "-screenshot");
// Can't call quit() in @AfterEach, or else it closes before we get the chance to take a screenshot
getTestInstanceDriver(context).realQuit();
}
@Override
public void testSuccessful(ExtensionContext context)
{
getTestInstanceDriver(context).realQuit();
}
@Override
public void testDisabled(ExtensionContext context, Optional<String> reason)
{
getTestInstanceDriver(context).realQuit();
}
@Override
public void testAborted(ExtensionContext context, Throwable cause)
{
getTestInstanceDriver(context).realQuit();
}
/**
* This class is used to extend itself, which creates a new instance of SeleniumMvcIntegrationTest as a TestWatcher.
* In the TestWatcher context, we want to access the driver belonging to the decorated instance; this convenience
* method provides the ability to do that.
*/
private MyChromeDriver getTestInstanceDriver(ExtensionContext context)
{
return ((SeleniumMvcIntegrationTest) context.getRequiredTestInstance()).driver;
}
}
我在调用realquit()
的地方,您可以轻松地使驱动程序打开。
tl; dr:如果结果对象引用[第一个操作数]不是null
,则将返回。否则,返回第二操作数(可能为null
)的值。此外,如果返回null,则操作员可以抛出异常。
猫王操作员是许多编程语言的一部分,例如Kotlin,但也是Groovy或C#。
我发现 wikipedia 定义非常准确:
在某些计算机编程语言中,猫王操作员
?:
是二进制运算符,如果该操作数为true ,否则评估并返回其第二操作数。它是三元条件运算符的变体,
? :
,在这些语言(以及其他许多语言)中找到:猫王操作员是 ternary操作员,其第二个操作数省略了。。
Kotlin尤其如此:
某些计算机编程语言对于此操作员具有不同的语义。 必须导致对象参考,而不是必须产生布尔值的第一操作数。如果结果对象引用不是
null
,则将返回。否则,将返回第二操作数(可能为null
)的值。如果第二操作数为null,则操作员也能够抛出异常。
一个例子:
x ?: y // yields `x` if `x` is not null, `y` otherwise.
x ?: throw SomeException() // yields `x` if `x` is not null, throws SomeException otherwise
可能是您要提取的ID在操作员数组中不存在的ID,这就是为什么您要获得一个空数组的原因,
无论ID是否存在,都可以运行此代码行
Might be the id that you are extracting is not there in the operators array, that's why you are getting an empty array
you can run this line of code whether the id is there or not
试图根据React-Redux Store过滤单个对象的ID过滤单个对象时获取一个空数组