1 条题解

  • 0
    @ 2025-10-10 19:32:49

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
    	int n,b,s,g,c = 0;
    	cin>>n;
    	
    	for(int i = 1;i <= n;i++){
    		b = i / 100;
    		s = i / 10 % 10;
    		g = i % 10;
    		
    		if(b==6 || s==6 || g==6){
    			c++;
    		}
    	}
    	
    	if(c % 2 == 0){
    		cout<<"playground";
    	}else{
    		cout<<"library";
    	}
    	return 0;
    }
    
    

    Java :

    import java.util.Scanner;
    public class Main{
    public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int t = 0;
    	if(n >= 10 && n <= 1000) {
    	for(int i = 1; i<= n; i++) {
    		if(i % 10 == 6 || i / 10 % 10 ==6 || i / 100 == 6) {
    			t++;
    			
    		}
    		
    		}
    		
    	if(t++ % 2 ==0) {
    	System.out.println("playground");
    }else {
    	System.out.println("library");
    }
    	
    		
    	}
    	
    	}
    	}
    

    Python :

    #接收输入
    n = int(input())
    #初始化总数c
    c = 0
    #循环遍历1~n
    for i in range(1, n + 1):
        #把i转换为字符串
        a = str(i)
        #把6转换为字符串
        b = '6'
        #如果6在a中,则c自加1
        if b in a:
            c += 1
    #如果总数是奇数,则打印输出“图书馆”,否则去“游乐场”
    if c % 2 != 0:
        print('library')
    else:
        print('playground')
    
    • 1

    信息

    ID
    881
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    1
    已通过
    0
    上传者