比赛 20130725暑期B班1测 评测结果 WAWWWWWWWW
题目名称 单词缩写 最终得分 10
用户昵称 Makazeu 运行时间 0.003 s
代码语言 C++ 内存使用 0.29 MiB
提交时间 2012-07-18 10:14:59
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cctype>
using namespace std;
int N,L,len;
const int MAXN=200;
char str[MAXN],word[MAXN];
char ffor[]="for";
char aand[]="and";
char the[]="the";

bool check(char *s1,char *s2)
{
	bool flag=1;
	if(strlen(s1)!=strlen(s2)) return false;
	for(int i=0;i<len;i++)
		if(s1[i]!=s2[i])
				return false;
	return true;
}

int main()
{
	freopen("abbreviation.in","r",stdin);
    	freopen("abbreviation.out","w",stdout);
	//freopen("in","r",stdin);
	scanf("%d\n",&N);
	int top;
	for(int i=1;i<=N;i++)
	{
		memset(str,'\0',sizeof(str));
		memset(word,'\0',sizeof(word));
		gets(str);
		L=strlen(str);
		str[L]=' ';
		L++;  top=-1;
		for(int j=0;j<L;j++)
		{
			str[j]=tolower(str[j]);
			if(str[j]!=' ')
			{
				word[++top]=str[j];
				continue;
			}
			len=strlen(word);
			if(len<3) goto end;
			if(check(word,ffor)) goto end;
			if(check(word,aand)) goto end;
			if(check(word,the))  goto end;
			printf("%c",toupper(word[0]));
			end:
			top=-1;
			memset(word,'\0',sizeof(word));
		}
		printf("\n");
	}
	return 0;
}

/*
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
string ans,word,str,del[3]={"for","and","the"};
int N,L,len;
int main()
{
    freopen("abbreviation.in","r",stdin);
    freopen("abbreviation.out","w",stdout);
    //freopen("in","r",stdin);
		//std::ios::sync_with_stdio(false);
    //cin>>N; getline(cin,str);
    scanf("%d\n",&N);
		char c;
    while(N--)
    {
        getline(cin,str);
        str.push_back(' ');
        L=str.length();
        transform(str.begin(),str.end(),str.begin(),::tolower);
        //cout<<str<<endl;
        word.clear();
        ans.clear();
        for(int i=0;i<L;i++)
        {
            c=str[i];
            if(c!=' ')
            {
                word.push_back(c);
                continue;
            }
            len=word.length();
            if(len<3) {word.clear(); continue;}
            if(word==del[0] || word==del[1] || word==del[2])
            {word.clear(); continue;}
            ans.push_back(word[0]);
            word.clear();
        }
				if(ans.length()==0) continue;
        transform(ans.begin(),ans.end(),ans.begin(),::toupper);
        if(ans.length())cout<<ans<<endl;
    }
    return 0;
}
*/