Description
输出n个字符串,把其中以字母A打头的字符串输出。
Input
第一行 n
第二行到第n+1行,每行一个字符串
Output
A打头的字符串
Sample Input
3
Ada
Bob
Alice
SampleOutput
Ada
Alice
代码如下:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int i,n;
string str[10];
cin>>n;
for (i=0;i<n;i++)
{
cin>>str[i];
}
for (i=0;i<n;i++)
{
if(str[i][0]=='A')
{
cout<<str[i]<<endl;
}
}
return 0;
}
运行结果:
又掌握了一个知识点,可以用a[ ][ ]表示字符串中的某个位置。