// from std import random.*
// from std import math.*
// from std import fs.*
// from std import console.*
// from std import convert.*
import std.console.*
import std.convert.*
var a = 1
var n = 0
func get(numMaxA: Int64,numMax: Int64): (Int64,Int64){
// var pNumber
// var SNumber
if(numMax==0){
return (0,-1)
}
var a=0
for (i in 0..=26) {
a=2*i+1+a
if(numMaxA == a){
return (2*i+1,numMax-a*2+1)
}
if(numMaxA < a){
return (2*(i-1)+1,numMax-((a-(2*i+1))*2-1))
}
}
return (0,-2)
}
main(){
// println("程序开始啦。")
// Console.stdOut.write("请输入:")
var cc=Console.stdIn.readln()
var rr = cc.getOrThrow()
let aaaa: Option<String> = cc
func getOrThrow(p: ?String): String{
match (p) {
case Some(x) => x
case None => "none"
}
}
func getOrThrowV(ov : ?Int64): Int64{
match(ov){
case Some(x) => x
case None => 0
}
}
var vvvv :String=getOrThrow(cc)
var vvvvindefOf:Int64 =getOrThrowV(vvvv.indexOf(32))
var n1:Int64 =0
var s1:String =""
if(!vvvv.isEmpty()){
var boo:Bool =false
var arr :Array<String> =vvvv.split(" ",118,)
try {
var coutnt1:Int64=0
if(arr.size <=2){
n1=Int64.parse(arr[0])
var arruu:String=arr[1]
var arrtt:Array<Rune>= arruu.toRuneArray()
s1=arrtt[0].toString()
for(cowuu in 1..arruu.size){
}
}else{
for (cow in arr){
println("cow = ${cow }")
var cowoo: String=cow
if(!cowoo.isEmpty()&&cowoo!=(" ")){
if(coutnt1==0){
n1=Int64.parse(cow)
coutnt1++
}else if(coutnt1==1){
var arrhh:Array<Rune> = cow.toRuneArray()
s1=arrhh[0].toString()
coutnt1++
}
}
}
}
var svv :Array<Rune>= s1.toRuneArray()
if(!svv[0].isAsciiPunctuation()){
s1=""
}
} catch (e: NegativeArraySizeException) {
}
}
var oo: (Int64,String)
var vvv=Some(543)
var numMax = 0;
if(n1 <= 1000){
numMax = n1;
} else{
numMax = 0;
}
var numMaxA=(numMax/2)+numMax%2
var varr1: (Int64, Int64) = get(numMaxA,numMax)
var t = varr1[0]
var p = varr1[1]
func getstart(){
var s:String =s1
var number = t
var count = 0
var numbercount=0
var c = 1
while(numbercount < t){
var countZero = (t-number)/2
var countNode = 0
while (countNode < countZero ){
print(" ")
countNode++;
}
while ( count < number){
count ++
print("${s}")
}
countNode = 0
while (countNode < countZero ){
print(" ")
countNode++;
}
println()
if (c == 1){
count =0
if(number > 1){
number =number - 2
}else {
c =2
}
}
if(c == 2 ){
count =0
if(number >= t)
{
// count =10;
numbercount=t+1;
}
number =number +2
}
}
}
if(s1.size>0){
getstart()
}else{
p=-1
print("0")
}
if(p!=-1){
print("${p}")
}
return 0
}
仓颉PAT程序设计 L1-002 打印沙漏 格式错误怎么处理?答案正确。
于 2024-07-29 20:31:29 首次发布