5 条题解

  • 2
    @ 2023-3-6 23:04:42

    P905 分离整数的各个数

    题面

    image


    额……这道题……有多种解……

    int类型解

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	long long n;
    	cin>>n;
    	if(n==0){
    		cout<<0;
    	}
    	while(n!=0){
    		cout<<n%10<<" ";
    		n/=10;
    	} 
    }
    

    这里还可以存在int数组里,不过属于脱裤子放屁了 image

    string/char类型不讲武德解

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	string a;
    	cin>>a;
    	for(int i=a.size()-1;i>=0;i--){
    		cout<<a[i]<<" ";
    	}
    }
    

    唔……这里也是,string.reverse()函数也是没有必要的,所以省掉这一步直接倒序输出 image


    END

  • 2
    @ 2022-10-18 16:33:36
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	long long n;
    	cin>>n;
    	while(n)
    	{
    		cout<<n%10<<" ";
    		n/=10;
    	}
    	return 0;
    }
    
    • 2
      @ 2022-9-5 18:10:58
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	long long n;
      	cin>>n;
      	while(n)
      	{
      		cout<<n%10<<" ";
      		n/=10;
      	}
      	return 0;
      }
      
      • 1
        @ 2026-1-26 19:32:10
        #include <iostream>
        #include <string>
        using namespace std;
        int main()
        {
            string a;
            cin >> a;
            for (int i = a.size() - 1;i >= 0;i--)
                cout << a[i] << ' ';
            return 0;
        }
        • -3
          @ 2021-11-26 22:35:54

          输入使用long long类型

          • 1

          信息

          ID
          905
          时间
          1000ms
          内存
          128MiB
          难度
          5
          标签
          递交数
          688
          已通过
          247
          上传者