题目描述
输入样例
2
zhongjiawei
haohaoxuexi
输出样例
235417
875843
思路
模拟
密码为6位数字,我们只需要将对应位置的数字求和,再将其按照规定变为一位数字即可
在给定的字符串中,下标为i的字符,对应贡献的位置应为i%6
AC代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
while(n --)
{
string s;
cin >> s;
vector<int> cnt(6);
for(int i = 0; i < s.size(); i ++) cnt[i % 6] += (int)s[i];
for(int i = 0; i < 6; i ++)
{
while(cnt[i] >= 10)
{
int sum = 0;
while(cnt[i])
{
sum += cnt[i] % 10;
cnt[i] /= 10;
}
cnt[i] = sum;
}
cout << cnt[i];
}
cout << endl;
}
return 0;
}
欢迎大家批评指正!!!