考虑到Ruby中的所有东西都是一个对象,我们可以打开irb并输入类似的东西4.class
并"Text".class
查看一个对象是哪个类,为什么这样做if.class
并且unless.class
没有给出返回值?
我正在玩UVa#494,我设法用以下代码解决它:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line;
while((line = in.readLine()) != null){
String words[] = line.split("[^a-zA-z]+");
int cnt = words.length;
// for some reason it is counting two words for 234234ddfdfd and words[0] is empty
if(cnt != 0 && words[0].isEmpty()) cnt--; // ugly fix, if has words and the first is empty, reduce one word
System.out.println(cnt);
}
System.exit(0);
}
} …
Run Code Online (Sandbox Code Playgroud)