3 条题解

  • 2
    @ 2024-1-7 16:38:41

    这是基础的数位拆分,当然也能用字符串

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        int a[10], cnt = 0;
        while (n)
        {
            a[++cnt] = n % 10;
            n /= 10;
        }
        cout << cnt << endl;
        for (int i = cnt; i >= 1; i--)
            cout << a[i] << " ";
        cout << endl;
        for (int i = 1; i <= cnt; i++)
            cout << a[i];
        cout << endl;
        return 0;
    }
    
    • 1
      @ 2023-10-10 23:30:36

      我来

      #include<bits/stdc++.h>
      using namespace std;
      int n,a[10],sum;
      int main()
      {
          cin>>n;
          while(n>0)
          {
              sum++;
              a[sum]=n%10;
              n/=10;
          }
          cout<<sum<<endl;
          for(int i=sum;i>=1;i--)
          {
              cout<<a[i]<<" ";
          }
          cout<<endl;
          for(int i=1;i<=sum;i++)
          {
              cout<<a[i];
          }
          return 0;
      }
      

      AC先赞后搬

      • 1
        @ 2023-1-16 9:49:17
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int n, s = 0, c = 0;
        	cin >> n;
        	//求n倒过来的数,求n的位数;
        	while(n != 0){
        		s = s*10 + n%10;
        		n /= 10;
        		c++;
        	} 
        	cout << c << endl;
        	//求s倒过来的数
        	int t = s;
        	while(t != 0){
        		cout << t%10 << " ";
        		t /= 10;
        	} 
        	cout << endl;
        	cout << s << endl;
        	return 0;
        }
        
        
        
        • 1

        信息

        ID
        959
        时间
        1000ms
        内存
        16MiB
        难度
        2
        标签
        递交数
        69
        已通过
        45
        上传者