總時間限制:
1000ms
內存限制:
65536kB
// 在此處補充你的代碼
描述
補充下列代碼,使得程序能夠按要求輸出
#include <iostream> #include <cstring> #include <vector> #include <cstdio> using namespace std;
int a[40]; int main(int argc, char** argv) { int t; scanf("%d",&t); while ( t -- ) { int m; scanf("%d",&m); for (int i = 0;i < m; ++i) scanf("%d",a+i); char s[100]; scanf("%s",s); CMyClass<int> b(a, m); CMyClass<char> c(s, strlen(s)); printf("%d %c\n", b[5], c[7]); } return 0; }
輸入
第一行是整數t表示數據組數
每組數據有兩行
第一行開頭是整數m,然後後面是m個整數(5 < m < 30)
第二行是一個沒有空格的字符串,長度不超過50
輸出
對每組數據 先輸出m個整數中的第5個,然後輸出字符串中的第7個字符。
"第i個"中的 i 是從0開始算的。
樣例輸入
1 6 1 3 5 5095 8 8 helloworld
樣例輸出
8 r
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;
template<class T>
class CMyClass
{
T *t;
public:
CMyClass(T t1[],int length)
{
t=new T[length];
for(int i=0;i<length;i++)
{
t[i]=t1[i];
}
}
T operator[](int ipos)
{
return t[ipos];
}
};
int a[40];
int main(int argc, char** argv) {
int t;
scanf("%d",&t);
while ( t -- ) {
int m;
scanf("%d",&m);
for (int i = 0;i < m; ++i)
scanf("%d",a+i);
char s[100];
scanf("%s",s);
CMyClass<int> b(a, m);
CMyClass<char> c(s, strlen(s));
printf("%d %c\n", b[5], c[7]);
}
return 0;
}