我在比较两个角色时遇到了麻烦.我写了一个非常基本的C问题来尝试命令行参数.
到目前为止,这是我的代码:
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char ch;
char *type = "";
char *gender = "";
int baby = 0;
int count = 0;
/* Options:
* -t = type of pet
* -g = gender
* -b = baby or adult
*/
while ((ch = getopt(argc, argv, "t:g:b")) != EOF)
switch (ch) {
case 't':
type = optarg;
break;
case 'g':
gender = optarg;
break;
case 'b':
baby = 1;
break;
default:
fprintf(stderr, …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个程序,将用户输入的子字符串与字符串数组进行比较.
#include <stdio.h>
#include <string.h>
char animals[][20] = {
"dogs are cool",
"frogs are freaky",
"monkeys are crazy"
};
int main() {
char input[10];
puts("Enter animal name: ");
fgets(input, sizeof(input), stdin);
int i;
for(i = 0; i < 3; i++) {
if(strstr(animals[i], input))
printf("%s", animals[i]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我进入青蛙时,例如它应该打印出"青蛙怪异"的信息,但它什么都没打印出来.
所以我试着写一行来每次打印出strstr()函数的值,它们都返回0,这意味着所有的比较都失败了.我不明白为什么,有人可以帮帮我吗?
部分原因是我必须实现二阶树的顺序遍历的非递归方法.我有点卡住了.这是我到目前为止:
public void inorder(BinaryTree v) {
Stack<BinaryTree> stack = new Stack<BinaryTree>();
stack.push(v);
System.out.println(v.getValue());
while(!stack.isEmpty()) {
while(v.getLeft() != null) {
v = v.getLeft();
stack.push(v);
System.out.println(v.getValue());
}
while(v.getRight() != null) {
v = v.getRight();
stack.push(v);
System.out.println(v.getValue());
}
stack.pop();
}
}
Run Code Online (Sandbox Code Playgroud)
我注意到它只打印出我树的左侧,例如
A
/ \
B C
/ \ / \
D E F G
/ \
H I
/ \
J K
Run Code Online (Sandbox Code Playgroud)
给 A B D H J
我正在尝试构建一个使用 Google Map API 的 Android 应用程序,并且我想将该项目放在 GIT 上。所以我有一个 API 密钥,此信息位于 AndroidManifest.xml 中,如下所示(我已将实际的 API 密钥替换为*key*此处
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value= *key* />
Run Code Online (Sandbox Code Playgroud)
我不希望将这些敏感信息推送到 git 上,但我无法 gitignore 这个文件。是否可以制作另一个具有密钥的 XML 文件,并让 AndroidManfiest.xml 从那里获取它(以便我可以 gitignore 这个文件)?
AndroidManifest.xml 有这段代码
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps"
android:launchMode="singleTop" />
Run Code Online (Sandbox Code Playgroud)
我注意到 label 属性从位于 res/values/strings.xml 中的另一个 XML 文件获取其值,因此:
label@意思?res文件夹中?我写的是一个存储程序ArrayList的Person对象(输入是从一个文本文件).
这是Person该类的代码,我将从中创建Person对象:
import java.io.Serializable;
public class Person implements Comparable<Person>, Serializable
{
private String firstName;
private String lastName;
private int age;
public Person(String firstName, String lastName, int age)
{
this.firstName = firstName;
this.lastName = lastName.toUpperCase();
this.age = age;
}
public int getAge()
{
return age;
}
public String getName()
{
return firstName;
}
/**
* @return a String of the details of a person in the format:
* Name: <firstName> <lastName> Age: <age> …Run Code Online (Sandbox Code Playgroud) 所以我正在关注tutorialspoint上的C++教程.
我真的很困惑,为什么新变量c的声明在声明一个新的枚举的同一行(对我来说看起来像一个typedef):
enum color { red, green, blue } c;
c = blue;
Run Code Online (Sandbox Code Playgroud)
如果我们想制作一个颜色类型的新变量,我就不能写
enum color {red,green,blue} newVar;
Run Code Online (Sandbox Code Playgroud)
正确?在C++中它是枚举颜色还是只是颜色?
我是Haskell的新手,我正在进行一些函数式编程工作.
以下是如何指定查找两个数字的最大值的示例:
max :: Integer -> Integer -> Integer
max x y
| x >= y = x
| otherwise = y
max' :: Integer -> Integer -> Integer
max' x y =
if x >= y then x else y
prop_max1 :: Integer -> Integer -> Bool
prop_max1 x y =
x <= max x y && y <= max' x y
Run Code Online (Sandbox Code Playgroud)
我想使用这个prop_max1函数,所以我写:
prop_max1 (max 1 2) (max' 1 2)
Run Code Online (Sandbox Code Playgroud)
返回True.
但如果我写
prop_max1((max 1 2) …Run Code Online (Sandbox Code Playgroud)