我遇到了 USACO 培训页面上的第一个问题。
任务是从 text.in 文件中请求两个字符串,将字符串转换为字母乘积的数字(其中 a=1、b=2、z=26),然后查看数字的余数是否/47 彼此相等(如果相等,打印“GO”,如果不相等,打印“STAY”)。
它在我的电脑上很好用,但是当我发送它时,它显示
运行 1:执行错误:您的程序以退出状态“1”退出。
------ Data for Run 1 [length=14 bytes] ------
COMETQ
HVNGAT
----------------------------
Your program printed data to stderr. Here is the data:
-------------------
Exception_in_thread_"main"_java.io.FileNotFoundException:_test.in_(No_such_file_or_directory)
at_java.io.FileInputStream.open(Native_Method)
at_java.io.FileInputStream.<init>(FileInputStream.java:106)
at_java.io.FileInputStream.<init>(FileInputStream.java:66)
at_java.io.FileReader.<init>(FileReader.java:41)
at_ride.main(Unknown_Source)
我尝试查看此http://cerberus.delos.com:790/usacoprobfix?a=VjAAvKvQucH,但我无法真正理解诸如“堆栈使用”或“越界”之类的术语。
它不接受我的代码的原因是因为它太慢了吗?我将不胜感激任何帮助解决这个问题。
/*
ID: Anon
LANG: JAVA
TASK: ride
*/
import java.io.*;
import java.util.*;
class ride
{
public static void main (String [] args) throws IOException
{
//input
BufferedReader br = new BufferedReader(new FileReader("test.in"));
//output
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.out")));
String nameComet = br.readLine();
String nameGroup = br.readLine();
int productComet = 1;
int productGroup = 1;
//loop through each letter in word
for(int i=0; i<nameComet.length(); i++)
{
//sets letter to char letter
char letter = nameComet.charAt(i);
//set number of letter to correspondnum
int numComet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(letter) + 1;
productComet *= numComet;
}
for(int i=0; i<nameGroup.length(); i++)
{
//sets letter to char letter
char letter = nameGroup.charAt(i);
//set number of letter to correspondnum
int numGroup = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(letter) + 1;
productGroup *= numGroup;
}
int modComet = productComet % 47;
int modGroup = productGroup % 47;
if (modComet == modGroup)
{
out.println("GO");
}
else
{
out.println("STAY");
}
//close everything
out.close();
System.exit(0);
}
}