2 solutions

  • 0
    @ 2026-1-26 8:35:21
    #include<bits/stdc++.h>
    #include<sstream>
    using namespace std;
    int main()
    {
        int n,s=0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            int a=i,b=i%10;
            bool c=1;
            while(a!=0)
            {
                if(a%10!=b)c=0;
                a/=10;
            }
            if(c)s++;
        }
        cout<<s;
    }
    
    • -1
      @ 2025-11-27 11:55:05

      C++ :

      #include <algorithm>
      #include <cstdio>
      using namespace std;
      int n, ans;
      int main() {
      	scanf("%d", &n);
      	for (int i = 1; i <= n; i++) {
      	int v = i % 10, t = i / 10, chk = 1;
      	while (t) {
      		if (t % 10 != v) chk = 0;
      			t /= 10;
      		}
      		ans += chk;
      	}
      	printf("%d\n", ans);
      	return 0;
      }
      
      • 1

      Information

      ID
      47
      Time
      1000ms
      Memory
      128MiB
      Difficulty
      8
      Tags
      # Submissions
      14
      Accepted
      9
      Uploaded By