5 条题解

  • 2
    @ 2024-2-5 17:00:45

    第一次写题解。。

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int n;
    	cin >> n;
    	while (n % 10 == 0) // 去除n末尾的0(们)
    		n /= 10;
    	if (n > 0) //判断正负数 如果为正数
    	{
    		while (n > 0) //分离数位 反向输出
    		{
    			cout << n % 10; // 求n的个位
    			n /= 10; // 将n整体右移一位(舍去已经输出的个位)
    		}
    	}
    	else // 如果为负数
    	{
    		n = abs(n); // 求绝对值(现去除负号)
    		cout << "-"; // 补上负号
    		while (n > 0) // 分离数位 * 2(同10-14行)
    		{
    			cout << n % 10;
    			n /= 10;
    		}
    	}
    }
    
    • 1
      @ 2024-4-6 19:48:17
      #include<bits/stdc++.h>
      using namespace std;
      char n[11],c[11];
      int q=0;
      int main()
      {
      	cin>>n;
          int len = strlen(n); 
          for(int i=len-1,j=0;i>=0;i--,j++) c[j]=n[i];// 赋值在c字符串上
          for(int i=0;i<len;i++){// 枚举起点
          	if(c[i]!='0') break;// 不为0时退出
      		else q++;// 为0是起点向后调
          }
          len=strlen(c);
          int f=0;
      	if(c[len-1]=='-'){
      		cout<<'-';
      		f=1;// 如果有负号把末尾的负号去掉
      	}
      	for(int i=q;i<len-f;i++) cout<<c[i];
          return 0;
      }
      

      字符串果然是个好东西👀️

      • 1
        @ 2023-7-29 14:24:55
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
            int n;
            cin>>n;
            if (n<0)
            {
                cout<<'-';
            }
            n=abs(n);
            while (n%10==0)
            {
                n/=10;
            }
            while (n>0)
            {
                cout<<n%10;
                n/=10;
            }
            return 0;
        } 
        
        • 1
          @ 2023-7-22 19:53:09
          #include <iostream>
          int main(){
              int q,a=0;std::cin>>q;
              if(q<0){std::cout<<"-";q*=-1;}
              while(q>0){
                  if(q%10!=0||a!=0){std::cout<<q%10;a=1;}
                  q/=10;}
              return 0;}
          
          • 1
            @ 2023-6-23 9:04:40
            #include<iostream>
            #include<iomanip>
            using namespace std;
            int main(){
            	int m;
            	cin>>m;
            	int q = 0;
            	if(m<0){
            		m*=-1;
            		while(m!=0){
            			q*=10;
            			q+=m%10;
            			m=m/10;
            		}
            		q = q*-1;
            	}
            	else{
            		while(m!=0){
            			q*=10;
            			q+=m%10;
            			m=m/10;
            		}	
            	}
            	cout<<q;
            }
            
            • 1

            信息

            ID
            185
            时间
            1000ms
            内存
            128MiB
            难度
            6
            标签
            递交数
            251
            已通过
            83
            上传者