2 条题解

  • 0
    @ 2025-10-2 9:36:48

    循环取位数

    
    #include<stdio.h>
    
    int main(){
    	int T,i;
    	int wei;
    	int a;
    	scanf("%d",&T);
    	for(i=0;i<T;i++){
    		wei=0;
    		scanf("%d",&a);
    		if(a==0){
    			printf("1\n");
    		}
    		while(a!=0){
    			wei++;
    			a/=10;
    		}
    		printf("%d\n",wei);
    	}
    	return 0;
    }
    
    • 0
      @ 2024-11-4 23:18:59

      #include<bits/stdc++.h> using namespace std; int main() { int T;

      cin>>T;
      
      int x;
      int ans[1024]={0};
      
      for(int i=1; i<=T; i++)
      {
      	cin>>x;
      	
      	while(x/10)
      	{
      		ans[i]++; //每一位累加 
      		x=x/10;
      	}
      }
      
      for(int i=1; i<=T; i++)
      {
      	cout<<ans[i]+1<<endl;
      }
      
      return 0;
      

      }

      • 1

      信息

      ID
      241
      时间
      2000ms
      内存
      256MiB
      难度
      3
      标签
      递交数
      308
      已通过
      165
      上传者