Description
現在,給你2個整形數字A和B。你的任務就是計算出A+B的結果C後,統計C中數字5出現的次數。
Input
輸入資料第一行包含一個整數T,表示測試資料的組數。對于每組測試資料:
輸入兩個整數a,b(-2*10^9<a,b<2*10^9)。兩個數字之間用空格隔開。
對于每組測試資料,輸出一行,包含一個整數,表示數字5出現的次數。
2
4 5
33 22
2
簡單題,注意溢出int
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a,b,c;
int T,ans;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&a,&b);
c=a+b;
ans=0;
for (c=c<0?-c:c;c;c/=10) if (c%10==5) ans++;
printf("%d\n",ans);
}
return 0;
}