标题统计
题目要求计算标题中字符数的个数,并且空格,换行符并不能计算在其中。于是我使用if语句进行限制,将大小写英文字母以及数字字符的ASCII码写进计数条件中,这样就可以只统计这些有效字符的个数了。
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main(){
int c=0;
char a[500];
for(int b=0;b<500;b++){
cin>>a[b];
if((a[b]>=97&&a[b]<=122)||(a[b]>=48&&a[b]<=57)||(a[b]>=65&&a[b]<=90)){
c++;
}
if(a[b]=='\0'){
break;
}
}
cout<<c<<endl;
return 0;
}
查看22道真题和解析