不使用字母e或数字5的Java输出或返回
对于PCG.SE,需要编写返回/输出前N个素数的函数/程序 但是,程序中不允许使用带有基本代码点的字符 其中两个字符是不使用字母e或数字5的Java输出或返回,java,escaping,Java,Escaping,对于PCG.SE,需要编写返回/输出前N个素数的函数/程序 但是,程序中不允许使用带有基本代码点的字符 其中两个字符是5和e。任一字母的代码点都包含一个5。因此,\u{codepoint}对这两个字母不起作用 使用转义符,我可以从代码中删除除return中的e以外的所有基本字符 我可以使用System.out或FileDescriptor.out,但两者都包含字母e 是否有任何方法可以在不使用e或5的情况下返回或输出 以下是我的转义字符代码供参考: int[]b(int b\u0029{
5
和e
。任一字母的代码点都包含一个5
。因此,\u{codepoint}
对这两个字母不起作用
使用转义符,我可以从代码中删除除return
中的e
以外的所有基本字符
我可以使用System.out
或FileDescriptor.out
,但两者都包含字母e
是否有任何方法可以在不使用e
或5
的情况下返回或输出
以下是我的转义字符代码供参考:
int[]b(int b\u0029{
int c,d,f[]\u003d{}\u003b
for(f\u003dj\u0061v\u0061.util.Arr\u0061ys.copy\u004ff(f,b\u0029\u003bb-->0\u003b\u0029
for(d\u003d0,c\u003d2\u003bf[b]<1\u003bf[b]\u003dd<1?c:f[b],d\u003d0,c\u002b\u002b\u0029
for(int h:f\u0029
d\u003dh>0&&c\u002fh*h\u003d\u003dc?1:d\u003b
return f;
}
int[]b(int b){
int c,d,f[]={};
for(f=java.util.Arrays.copyOf(f,b);b-->0;)
for(d=0,c=2;f[b]<1;f[b]=d<1?c:f[b],d=0,c++)
for(int h:f)
d=h>0&&c/h*h==c?1:d;
return f;
}
int[]b(intb\u0029{
int c,d,f[]\u003d{}\u003b
对于(f\u003dj\u0061v\u0061.util.Arr\u0061ys.copy\u004ff)(f,b\u0029\u003bb-->0\u003b\u0029
对于(d\u003d0,c\u003d2\u003bf[b]0;)
对于(d=0,c=2;f[b]我找到了一种不使用System.out
、FileDescriptor.out
或return
输出素数的方法。我的方法不使用“素数”字符
这是非常棘手的,因为e
在Java包名、类名和方法名中随处可见。而且,S
必须被禁止,因为它是Unicode中的数字83
,并且83
是prime。它的Unicode转义\u0053
包含一个5
,其Unicode字符53
也是素数。以下是根据这些规则我们不能使用Unicode转义的所有字符:
%
(37是素数,\u0025
有一个5
)
5
(53是素数,\u0035
有一个5
)
S
(83是素数,\u0053
有一个5
)
Y
(89是素数,\u0059
有一个5
)
e
(101是素数,\u0065
有一个5
)
这消除了:
- 任何方法,如
toString
,fromString
,parseInt
,valueOf
,以及values
java.beans
,java.net
,java.lang.reflect
包
Class.forName
- 使用新的
运算符
- 日志框架通常使用包含
e
的Logger
类
以下是可以使用Unicode转义的字符:
)
(41为素数,允许使用\u0029
)
+
(43为素数,允许使用\u002b
)
/
(47为素数,允许使用\u002f
)
;
(59为素数,允许使用\u003b
)
=
(61为素数,允许使用\u003d
)
C
(67为素数,允许使用\u0043
)
G
(71为素数,允许使用\u0047
)
I
(73为素数,允许使用\u0049
)
O
(79为素数,允许使用\u004f
)
a
(97为素数,允许使用\u0061
)
k
(107为素数,允许使用\u006b
)
q
(113为素数,允许使用\u0071
)
试图生成一个异常,其消息包含所需的输出,这是满足Java要求的唯一方法。我们不能使用检查异常,因为我能找到的几乎所有检查异常都在其名称中使用e
,并且在通过Throwable
的每个超类中都使用e抛出包含异常名称的
子句,该异常名称包含e
。我无法扩展
任何类,因为扩展
包含e
s
这就留下了未检查的异常。最有可能的用法是一个IllegalArgumentException
,它不是由该代码直接创建的,而是由一个内置的调用创建的,该调用抛出一个IllegalArgumentException
Enum
s会有所帮助,除非valueOf
包含e
javax.crypto.Mac.getInstance
有一个e
;它无论如何都会抛出一个选中的异常
javax.naming.ldap.Rdn.unescapeValue(“\\b”+stringFormOfOutput)
通过异常输出列表,但该方法具有e
java.util.UUID.fromString
通过异常输出列表,但该方法有一个S
抛出一个
javax.xml.bind.JAXB.unmarshal(stringFormOfOutput,Long.class)
通过DataBindingException
输出列表,没有e
现在我们所要做的就是将int[]
转换为字符串
。通过将数组连接到“
字符串转换不起作用,因为。数组。toString
因S
而失效
我们可以使用array.asList
从数据中获取List
。但是,使问题更加复杂。将f
的类型更改为Integer[]
将不起作用,这将产生e
。将f
的类型更改为Long[]
会起作用
数组到字符串的转换如下所示
Long c,d,f[]...
""+Arrays.asList(f)
代替return
语句,使方法void
,并调用unmarshal
。使用Long
意味着需要进行一些其他调整,例如使用Long
文本和fill
用零而不是默认的null
填充数组
void b(int b){
Long c,d,f[]={};
for(f=java.util.Arrays.copyOf(f,b),Arrays.fill(f,0L);b-->0;)
for(d=0L,c=2L;f[b]<1;f[b]=d<1?c:f[b],d=0L,c++)
for(long h:f)
d=h>0&&c/h*h==c?1:d;
javax.xml.bind.JAXB.unmarshal(""+Arrays.asList(f),Long.class);
}
但是
void b(int b\u0029{
Lon\u0067 c,d,f[]\u003d{}\u003b
for(f\u003dj\u0061v\u0061.util.Arr\u0061ys.copy\u004ff(f,b\u0029,Arr\u0061ys.fill(f,0L\u0029\u003bb-->0\u003b\u0029
for(d\u003d0L,c\u003d2L\u003bf[b]<1\u003bf[b]\u003dd<1?c:f[b],d\u003d0L,c\u002b\u002b\u0029
for(lon\u0067 h:f\u0029
d\u003dh>0&&c\u002fh*h\u003d\u003dc?1:d\u003b
j\u0061v\u0061x.x\u006dl.bind.JAXB.un\u006d\u0061rsh\u0061l(""\u002bArr\u0061ys.\u0061sList(f\u0029, Lon\u0067.cl\u0061ss\u0029\u003b
}
Exception in thread "main" javax.xml.bind.DataBindingException: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)]
at javax.xml.bind.JAXB.unmarshal(JAXB.java:208)
at Main.b(Main.java:34)
at Main.main(Main.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:206)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:181)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:235)
at javax.xml.bind.JAXB.unmarshal(JAXB.java:205)
... 7 more
Caused by: java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:609)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:799)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203)
... 10 more
st\u0061tic
{
b(10\u0029\u003b
}
st\u0061tic void b(int b\u0029{
// ...
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:87)
Caused by: javax.xml.bind.DataBindingException: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)]
at javax.xml.bind.JAXB.unmarshal(JAXB.java:208)
...