首页 > 解决方案 > 该代码仅采用第一个测试用例的输入

问题描述

//即使提供了多个测试用例,此代码也只接受用户的第一个输入。

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    { 
      int t,n,ans,a, b, d, c, i,j; 
      cin>>t;
      while(t>0)
      { 
       c=0;
       cin>>n; 
       d = n;
       while(n!=0)
       {
         a = n; n=n/10; b = a % 10;
         if (d % b == 0)  c++; 
         else continue; 
       }
       cout<<c<<"\n";
       t--; 
      }
      return 0;
    }

标签: c++14

解决方案


在同一个循环中替换while(t>0)while(t--)删除t--;while


推荐阅读