您的位置:首页 > 产品设计 > UI/UE

2076 Problem F Quick Brown Fox

2016-06-09 20:51 387 查看

题目描述



A pangram is a phrase that includes at least one occurrence of each of the 26 letters, ‘a’. . .‘z’. You’re probably familiar with this one: “The quick brown fox jumps over the lazy dog.”
Your job is to recognize pangrams. For phrases that don’t
contain every letter, report what letters are missing. We’ll say that a
particular letter occurs in the phrase if it occurs as either upper case or
lower case.

输入

Input starts with a line
containing an integer 1 ≤ N ≤ 50. The next N lines are each a single
phrase,possibly containing upper and lower case letters, spaces, decimal digits
and punctuation characters ‘.’,‘,’, ‘?’, ‘!’, ‘’’ and ‘"’. Each phrase contains
at least one and no more than 100 characters.

输出

For each input phrase, output
“pangram” if it qualifies as a pangram. Otherwise, output the word “missing”
followed by a space and then the list of letters that didn’t occur in the
phrase. The list of missing letters should be reported in lower case and should
be sorted alphabetically.

样例输入

3
The quick brown fox jumps over the lazy dog.
ZYXW, vu TSR Ponm lkj ihgfd CBA.
.,?!’" 92384 abcde FGHIJ

样例输出

pangram
missing eq
missing klmnopqrstuvwxyz

解题心得:
  题目的意思是,输入一行字符(大小写皆可),判断是否为“全字母短句”,是则输出pangram,否则输出missing 加缺少的字母;
  此题为水题,但是我却做了很久,主要原因是写完后一直在找错,结果最后发现输出错了。
  老是犯些低级错误,丢三落四结果导致白白付出很多时间。
代码:


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int b[30];

void is(char a_z[],char a){
int ii;
for(ii=0;ii<26;ii++){
if(a==a_z[ii]||a==a_z[ii]-32){
b[ii]=1;
}
}
}

int main()
{
int n;
int j=0;
char a[105];
char a_z[26];
strcpy(a_z,"abcdefghijklmnopqrstuvwxyz");
memset(b,0,30*sizeof(int));
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++){
j=0;
memset(a,'\0',105*sizeof(char));
gets(a);
for(int i2=0;a[i2]!='\0';i2++){
is(a_z,a[i2]);
}
for(int i3=0;i3<26;i3++){
if(b[i3]==0){
j++;
}
}
if(j==0){
printf("pangram\n");
}
else{
printf("missing ");
for(int j1=0;j1<26;j1++){
if(b[j1]==0){
printf("%c",a_z[j1]); //我把a_z写成了a,结果好久好久都没找出错误来!!
}
}
printf("\n");
}
memset(b,0,30*sizeof(int));

}
int ab;
cin>>ab;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: