3 条题解

  • 2
    @ 2024-2-16 10:53:30

    用函数,不迷路!

    已AC,请放心食用

    #include <iostream>
    using namespace std;
    int six(int n)
    {
        int x = n;
        bool f = false;
        while (x > 0)
        {
            if (x % 10 == 6)
            {
                f = true;
                break;
            }
            x /= 10;
        }
        return f;
    }
    int main()
    {
        int n, num = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            if (six(i))
            {
                num++;
            }
        }
        if (num % 2 == 1)
        {
            cout << "library";
        }
        else
        {
            cout << "playground";
        }
        return 0;
    }
    

    养成好习惯,看后点个赞😎!

    • 0
      @ 2023-10-10 23:57:01

      没人发,我来

      #include<bits/stdc++.h>
      using namespace std;
      int n,a[1005],sum,num;
      int main()
      {
          cin>>n;
          for(int i=1;i<=n;i++)
          {
              int m=i;
              while(m>0)
              {
                  if(m%10==6)
                  {
                      sum++;
                      break;
                  }
                  m/=10;
              }
          }
          if(sum%2==0)
          {
              cout<<"playground";
          }
          else
          {
              cout<<"library";
          }
          return 0;
      }
      
      
      • 0
        @ 2023-1-16 14:56:02
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int n, m, k = 0;
        	cin >> n;
        	for (int i = 1; i <= n; i++){
        		m = i;
        		//短除法判断各个位是否有等于6
        		while(m > 0){
        			if(m%10 ==6){
        				k++;//计数器
        				break; 
        			}
        			m /= 10;
        		} 
        	}
        	//判断含有6的数字的个数是奇数还是偶数
        	//是奇数,就去图书馆,否则就去游乐场
        	if(k % 2 == 0){
        		cout << "playground";
        	} else {
        		cout << "library";
        	}
        	return 0;
        }
        
        
        • 1

        信息

        ID
        960
        时间
        1000ms
        内存
        128MiB
        难度
        3
        标签
        递交数
        78
        已通过
        41
        上传者