描述
填写代码,按要求输出结果
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
// 在此处补充你的代码
string int2string(int x) { return to_string(x); }
int int2squareint(int x) { return x * x; }
int string2int(string str) {
int res = 0;
for (string::iterator iter = str.begin(); iter != str.end(); ++iter)
res += *iter;
return res;
}
string string2longerstring(string str) { return str + str; }
int main() {
int t;
cin >> t;
while (t--) {
int b1[10];
for (int i = 0; i < 10; ++i)
cin >> b1[i];
A<int, 10> a1 = b1;
cout << a1.sum(2, 6, int2squareint) << endl;
cout << a1.sum(2, 6, int2string) << endl;
string b2[4];
for (int i = 0; i < 4; ++i)
cin >> b2[i];
A<string, 4> a2 = b2;
cout << a2.sum(0, 3, string2int) << endl;
cout << a2.sum(0, 3, string2longerstring) << endl;
}
return 0;
}
输入
第一行是整数n,表示有n组数据
每组数据有2行
第一行是10个整数
第二行是4个不带空格的字符串,它们之间用空格分隔
输出
先输出10个整数里面的第3个到第7个的平方和
再输出10个整数里从第3个到第7个,按照字符串的方式,顺序连接的结果
再输出4个字符串里,第1个到第4个串中,所有字符的ASCII码加和得到的整数
再输出4个字符串里,第1个到第4个串,分别复制一遍后,按照字符串的方式,顺序连接的结果。
样例输入
1
1 2 3 4 5 6 7 8 9 10
Machine , Learning !
样例输出
135
34567
1586
MachineMachine,,LearningLearning!!
提示
3^2 + 4^2 + 5^2 + 6^2 + 7^2 = 135
“Machine,Learning!”中所有字符的ASCII码相加为1586