题解
2023-11-13 12:55:13
发布于:广东
22阅读
0回复
0点赞
设一个变量x,每移动一次就更新x
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
string a;
cin >> a;
int x = '1';
int ct = 0;
for(int i = 0; i < 4; i++){
if(a[i] == '0'){
a[i] = '9' + 1;
}ct += max(a[i] - x, -a[i] + x) + 1;
x = a[i];
}cout << ct << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个