4 条题解

  • 0
    @ 2026-9-15 11:07:09

    简单题(Python) 1.只需要遍历循环2到2021,并把相应的int转换成str,再次循环,用j去遍历,只要s[j]=="2", res+=1,即可 2.最后print(res)

    res = 0
    for i in range(2,2021):
        s = str(i)
        for j in range(len(s)):
            if s[j]=="2":
                res+=1
    print(res)
    
    
    • 0
      @ 2024-11-23 15:55:13

      n=0 for i in range(1,2021): while (i/10!=0): if i%10==2: n+=1 i=int(i/10)

      • 0
        @ 2024-4-8 10:52:12
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        int n=0;
        for(int i=1;i<2021;i++)
        {
        int b;
        b=i;
        while(b)
        {
        if(b%10==2)
        {
        n++;
        }
        b=b/10;
        }
        }
        cout<<n<<endl;
        return 0;
        }
        
        • 0
          @ 2024-4-7 0:58:01

          【2020年省赛B组】试题A: 门牌制作

          题解

          简单模拟题。

          • 枚举数字120221\sim 2022,把每个数按照十进制分解,再统计2出现的次数即可。
          • 也可以将每个数字都转换为字符串,然后直接统计这些字符串总共有多少个字符2。

          最后的答案为624

          提交代码

          #include<bits/stdc++.h>
          using namespace std;
          int get(int x)
          {
          	int cnt = 0;
          	while(x)
          	{
          		if(x % 10 == 2) cnt++;
          		x /= 10;
          	}
              return cnt;
          }
          
          signed main()
          {
              ios::sync_with_stdio(false);
              cin.tie(0);
          	int ans = 0;
          	for(int i = 1; i <= 2020; i++)
          	{
          		ans += get(i);	
          	}
          	cout << ans << "\n";
              return 0;
          }
          
          • 1

          信息

          ID
          986
          时间
          1000ms
          内存
          256MiB
          难度
          1
          标签
          递交数
          170
          已通过
          62
          上传者