使用Scala 2.10+字符串可以进行插值.所以我有这个问题.你怎么能这样做:
println(f"$foo(100,51)%1.0f" )
Run Code Online (Sandbox Code Playgroud)
考虑foo是一个函数,如:
def foo(x1:Int , x2:Int) : Double = { ... }
Run Code Online (Sandbox Code Playgroud)
根据我的理解,这被评估的方式使得foo被认为没有参数因为我得到的消息是:
missing arguments for method foo in object bar;
follow this method with `_' if you want to treat it as a partially applied function
Run Code Online (Sandbox Code Playgroud)
我尝试使用括号,但仍然会出现错误.
我想要一个希腊字母数组,这就是我所做的:
wchar_t pcletters[30] = {'?' , '?' , '?' , '?' , '?' , '?' , '?' , '?', '?' , '?' , '?' , '?' , '?' , '?','?' , '?' , '?' , '?' , '?' , '?' , '?' , '?' , '?' , '?' , '?', '?' , '?' , '?' , '?' , '?' , '?'} ;
Run Code Online (Sandbox Code Playgroud)
我也包括 <locale.h>并且有一条线setlocale(LC_CTYPE, "") .
但是我得到警告警告:多字符字符常量[-Wmultichar].此外,当我通过执行以下操作检查其中一个字母是否在用户输入中时:
if (userword[i] == pcletters[j]) {//do stuff}
Run Code Online (Sandbox Code Playgroud)
它似乎不起作用. - 为什么我会收到这个警告? - 有没有办法改变pcletters的方式,以便能够比较 …
我正在设置指针,如上面的代码中所示.问题是无论我尝试过什么,malloc都会抛出一个分段错误.这是代码:
wchar_t **Words ;
int lc = lineCounter() ;
**Words = malloc( lc * sizeof(int) ) ;
if (**Words == NULL) return -1 ;
Run Code Online (Sandbox Code Playgroud)
lineCounter函数只是一个返回文件中行数的函数.所以我尝试做的是释放一些内存,将指针保存到lc个单词.
以下是我的想法:

有两种方法(至少)在C中初始化一个数组.有什么区别
int array[] = {1,2,3,4,5,6,7,8,9} ;
Run Code Online (Sandbox Code Playgroud)
和:
int array[100] = {1,2,3,4,5,6,7,8,9} ;
Run Code Online (Sandbox Code Playgroud)
我并不是指内存分配方式.也许引发这个问题的事情会有用,以便理解我的问题.
我希望通过迭代来获得int数组的长度.这是代码:
#include <stdio.h>
#include <stdlib.h>
int array[] = {1,2,3,4,5,6,7,8,9} ;
int i = 0 ; // i is length
while( array[i] ) {
printf("%d\n" , array[i] ) ;
i++ ;
}
printf("%d\n" , i) ;
Run Code Online (Sandbox Code Playgroud)
我注意到当我使用array []时,由于某种溢出,长度有时是错误的,但是当我使用数组[100]时,长度总是正确的.这两者有什么区别?它与'\ 0'字符有关吗?
所以我得到了这个小块代码.主要功能是打印主要功能.什么印刷?这是某种地址吗?
int main() {
printf( "%d", main ) ;
}
Run Code Online (Sandbox Code Playgroud) 我正在解决这个问题(在http://projecteuler.net/problem=55找到),但我无法解决它,所以我搜索了答案。似乎我的代码给出的答案仅差 3 (mine: 246 , right: 249)。有人发现错误会很好。我已经尝试了3个小时了......
这是我的代码:
from time import time
def rev(x):
return int(str(x)[::-1])
def Palindrome(x):
if x == rev(x): return True
else : return False
def test(x):
steps = 0
while True :
if not Palindrome(x):
steps += 1
else:
return False
if steps > 50 :
return True
x += rev(x)
def main():
starttime = time()
lychrel = 0
for i in range(1,10000):
if test(i) : lychrel += 1
elapsed = time() - …Run Code Online (Sandbox Code Playgroud) c ×4
arrays ×1
pointers ×1
printf ×1
python ×1
python-2.7 ×1
scala ×1
scala-2.10 ×1
wchar-t ×1