您的位置:首页 > 其它

UVa 492 - Pig-Latin

2013-11-03 17:40 1031 查看
题目:字符串转化,如果是辅音开头把单词的开头放到最后,然后后加上ay后缀即可。

分析:简单题。直接转化即可,记录每个单词的开始和结束,处理即可。

注意:题目没有给出数据范围,数组开大一点RE两次╮(╯▽╰)╭,感谢七轮 的指出。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

char temp[1000005];

int isab( char c )
{
	if ( c >= 'a' && c <= 'z' )
		return 1;
	if ( c >= 'A' && c <= 'Z' )
		return 1;
	return 0;
}

int vowel( char c )
{
	if ( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' )
		return 1;
	if ( c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' )
		return 1;
	return 0;
}

int main()
{
	while ( gets(temp) ) {
		int s = 0,t = 0;
		while ( temp[s] ) 
			if ( !isab(temp[s]) ) {
				printf("%c",temp[s ++]);
				t = s;
			}else if ( isab(temp[t]) )
				t ++;
			else {
				if ( !vowel(temp[s]) ) {
					for ( int i = s+1 ; i < t ; ++ i )
						printf("%c",temp[i]);
					printf("%c",temp[s]);
				}else 
					for ( int i = s ; i < t ; ++ i )
						printf("%c",temp[i]);
				printf("ay");
				s = t;
			}
		printf("\n");
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: