记录编号 |
114283 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[暑假培训2012] 单词缩写 |
最终得分 |
100 |
用户昵称 |
Bokjan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.005 s |
提交时间 |
2014-07-28 15:16:38 |
内存使用 |
0.29 MiB |
显示代码纯文本
#include <cstdio>
#include <cstring>
const int MAX_LENGTH = 100 + 4;
void StrToUpper(char *str)
{
int len = strlen(str);
for(int i = 0; i < len; i++)
if(str[i] >= 'a' && str[i] <= 'z')
str[i] -= 32;
}
bool Split(char *dest, char *src, int &p, int len)
{
int q = 0;
while(src[p] != ' ' && p < len)
dest[q++] = src[p++];
dest[q] = 0;
p++;
if(q)
return true;
else
return false;
}
int main(void)
{
FILE *fin = fopen("abbreviation.in", "r");
FILE *fout = fopen("abbreviation.out", "w");
int n;
char in[MAX_LENGTH];
fscanf(fin, "%d", &n);
fgets(in, MAX_LENGTH - 1, fin);
while(n--)
{
fgets(in, MAX_LENGTH - 1, fin);
int len = strlen(in);
while((in[len - 1] > 'z')||(in[len - 1] > 'Z' && in[len - 1] < 'a')||in[len - 1] < 'A')
in[--len] = 0;
StrToUpper(in);
char word[MAX_LENGTH];
int ptr = 0;
while(Split(word, in, ptr, len))
if(!strcmp(word, "AND")||!strcmp(word, "FOR")||!strcmp(word, "THE")||strlen(word) < 3)
continue;
else
fprintf(fout, "%c", word[0]);
fprintf(fout, "\n");
}
fclose(fin);
fclose(fout);
return 0;
}