[^1]
例题描述:一篇文章中含有三行文字,每行文字80个字符,要求统计大写字母小写字母,数字空个及其他
【输入样例】
3** &shdjhlhjlskjhsj e3$#&#&#& @^@ hldjslihjwlhjjwh
ejlhijsljh;j $#&#&#&!@13536 52@@^ lakhylkajhlsjh
eiylisdjg;#^^ 356236……%
【样例输出】
41
54
43
58
44
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int i,len=0;
char temp[100];
int low,high,digit,space,other;
FILE *in=fopen("a.txt","r");
for(i=0;!feof(in);i++)
{
fscanf(in,"%c",&temp[i]);
len++;
}
for(i=0;i<len-1;i++)
{
if(temp[i]>='a'&&temp[i]<='z')
low++;
else if(temp[i]>='A'&&temp[i]<='Z')
high++;
else if(temp[i]==' ')
space++;
else if(temp[i]>='0'&&temp[i]<='9')
digit++;
else
other++;
}
cout<<low<<'\n'<<high<<'\n'<<space<<'\n'<<digit<<'\n'<<other<<'\n';
fclose(in);
}
[^2]
修罗王和邪狼在逃跑过程中,警探要从厚厚的电话中查找到失窃车主的姓名。
【输入格式】
输入第一行为整数N表示姓名,一下N行每一行为一个姓名,最后一行为字符串,为查找姓名。姓名数不超过50,
姓名长度不超过50.
【输入样例】
3
Zhang
Chu
Li
Chu
【输出样例】
2
#include<iostream>
#include<cstring>
using namespace std;
#define N 100
int main()
{
int i,n,len;
char str[N][N];
char str1[N];
cin>>n;//输入行数
for(i=0;i<n;i++)
cin>>str[i];
cin>>str1;//输入需要查找的名字
for(int j=0;j<n;j++)
{
if(strcmp(str[j],str1)==0)//相同返回零
{
cout<<j+1;
break;
}
}
}