//考试座位号
from std import console.*
from std import convert.*
from std import collection.*
// import std.collection.*
//import std.console.*
//import std.convert.*
func getOrThrow(p: ?String): String{
match (p) {
case Some(x) => x
case None => "none"
}
}
func isNumber(number_string :String):Bool{
var number_rune :Array<Rune>=number_string.toRuneArray()
for(number in number_rune){
if(!number.isAsciiNumber()&&number.toString() !=" "){
return false
}
}
return true
}
func getInput():String{
var input=Console.stdIn.readln()
var rr = input.getOrThrow()
let input_to_strig: Option<String> = input
var input_to_strig_to :String=getOrThrow(input_to_strig)
if(isNumber(input_to_strig_to)){
return input_to_strig_to
}
return ""
}
var array_groups = ArrayList<Array<String>>()
func getExamSeatsGroupsSplit(seat_number: Int64):Array<String>{
var seat:String= getInput()
if(!seat.isEmpty()){
var temp_array_seats :Array<String> =seat.split(" ",118,)
var array_seats = Array<String>(3, item: "")
var count=0;
for (i in temp_array_seats){
if(i != " "&& !i.isEmpty()&& i.size>0){
if(count<3){
if(i.size==16){
array_seats[0]=i
count=1
}else if(count == 1&&1<= Int64.parse(i)&& Int64.parse(i)<=seat_number&&0!= Int64.parse(i)){
array_seats[count]=i
count++
}else if(count == 2&&1<= Int64.parse(i)&& Int64.parse(i)<=seat_number&&0!= Int64.parse(i)){
array_seats[count]=i
count++
}
}
}
}
if(!array_seats.isEmpty()&&array_seats[0].size>0
&&array_seats[1].size>0&&array_seats[2].size>0){
return array_seats
}else{
return [""]
}
}
return [""]
}
func getExamSeatsGroups(group_total :Int64){
var count_number=0
while(count_number<group_total){
var test_array:Array<String>=getExamSeatsGroupsSplit(group_total)
if(!test_array.isEmpty()&&test_array.size>1){
var count =0;
for(i in array_groups){
if(i[0]==test_array[0]||test_array[1]==i[1]||test_array[2]==i[2]){
count++
}
}
if(count==0){
array_groups.append(test_array)
count_number++;
}
}else{
}
}
}
func getStartExamSeats(exam_seats : String){
if(!exam_seats.isEmpty()){
var exam_seats_group : Int64=Int64.parse(exam_seats)
getExamSeatsGroups(exam_seats_group)
}
}
var check_array_groups =ArrayList<String>()
func getCheckArrayGroupsSplit(){
var seat:String= getInput()
if(!seat.isEmpty()){
var temp_array_seats :Array<String> =seat.split(" ",118,)
var count=0;
for (i in temp_array_seats){
if(i != " "&& !i.isEmpty()){
for ( array_in_group in array_groups){
if(i==array_in_group[1]){
check_array_groups.append(i)
count++
}
}
}
}
}
return 0
}
func getCheckArray(check_string :String){
getCheckArrayGroupsSplit()
}
func printlnSeats(){
for(i in check_array_groups){
for(j in array_groups){
if(i == j[1]&&j[1].size>0){
println("${j[0]} ${j[2]}")
}
}
}
}
func getStartGetCheckNumber(check_number : String){
if(!check_number.isEmpty()){
var count_seats=Int64.parse(check_number)
getCheckArrayGroupsSplit()
printlnSeats()
}
}
func printlnAllSeat(){
for(i in array_groups){
println("${i[0]} ${i[1]} ${i[2]}")
}
}
main(){
var get_seats:String=getInput()
if(!get_seats.isEmpty()){
var get_seats_int64:Int64 = Int64.parse(get_seats)
if(get_seats_int64<=1000){
getStartExamSeats(get_seats)
var get_check_number:String=getInput()
if(!get_check_number.isEmpty()){
var get_check_number_int64:Int64=Int64.parse(get_check_number)
if(get_check_number_int64<=get_seats_int64&&get_check_number_int64>0){
getStartGetCheckNumber(get_check_number)
}
}
}
}
return 0
}
仓颉PAT程序设计 L1-005 考试座位号
于 2024-07-30 19:57:13 首次发布