文章
68
粉丝
691
获赞
26
访问
578.3k
string s; queue<string>q;
vector<string> v;
for (int i = 1; i <= 9; i++)
q.push(to_string(i));
while (!q.empty()) {
string t = q.front(); q.pop();
int tmp = t.size();
if (tmp >= 10)continue;
if (t.size() > 1)v.push_back(t);
if (t[tmp - 1] - 1 >= '0')q.push(t + char(t[tmp - 1] - 1));
if (t[tmp - 1] + 1 <= '9')q.push(t + char(t[tmp - 1] + 1));
}
cin >> T;
while (T--) {
cin >> l >> r;
string sr = to_string(r), sl = to_string(l);
int cnt = 0;
for (int i = 0; i < v.size() && cmp(v[i], sr); i++) {
if (!cmp(v[i], sl) || sl == v[i])
cnt++;
}
cout << cnt << endl;
}
登录后发布评论
暂无评论,来抢沙发