C语言习题 输出A打头的字符串
时间: 1ms 内存:128M
描述:
输出n个字符串,把其中以字母A打头的字符串输出。
输入:
第一行 n第二行到第n+1行,每行一个字符串
输出:
A打头的字符串
示例输入:
3
Ada
Bob
Alice
示例输出:
Ada
Alice
提示:
参考答案(内存最优[752]):
#include<stdio.h>
int main()
{
char F[100][100],f[100],c;
int n,m,a,b;
scanf("%d\n",&n);
for(m=1;m<=n;m++)
{
a=0;
while(scanf("%c",&c)!=EOF)
{
if(c=='\n') break;
F[m][a]=c;
a++;
}
f[m]=a;
}
for(m=1;m<=n;m++)
{
if(F[m][0]=='A')
{for(b=1;b<=f[m];b++)
printf("%c",F[m][b-1]);
printf("\n");
}
}
return 0;
}
参考答案(时间最优[0]):
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>str;
if(str[0]=='A')
cout<<str<<endl;
}
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。