求助一道题困惑了我几天的题目
  • 板块学术版
  • 楼主happybob
  • 当前回复0
  • 已保存回复0
  • 发布时间2020/12/1 20:38
  • 上次更新2023/11/5 06:56:41
查看原帖
求助一道题困惑了我几天的题目
332914
happybob楼主2020/12/1 20:38

题目

代码:

//#include <iostream>
//#include <cstdio>
//#include <string>
//using namespace std;
//
//inline bool judge(const char& c)
//{
//	return (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U');
//}
//int main()
//{
//	string s;
//	ios::sync_with_stdio(false);
//	while(getline(cin, s))
//	{
//	    int len = s.length() - 1; 
//	    string tmp = "";
//	    for(register int i = 0; i <= len; i++)
//	    {
//	        bool f = true;
//	        if(isalpha(s[i]))
//	        {
//                char now = s[i];
//	            if(judge(s[i]))
//	            {
//	                cout << s[i];
//	                f = false;
//                }
//                while(isalpha(s[++i])) cout << s[i];
//                if(f)
//                {
//                    cout << now;
//                }
//                i--;
//                cout << "ay";
//            }
//            else
//            {
//                cout << s[i];
//            }
//        }
//        cout << "\n";
//    }
//	return 0;
//}

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

bool pd(char c)
{
	return (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U');
}

int main()
{
   // freopen("C:\\ansop.txt", "w", stdout);
	string s;
	char b;
	while(cin >> s)
	{
		bool f = false;
		int len = s.length() - 1;
		if(s[len] == '.') f = true;
		if(pd(s[0]))
		{
			if(f)
			{
				cout << s.substr(0, len) << "ay.";
			}
			else
			{
				cout << s << "ay";
			}
		}
		else
		{
			for(int i = 1; i <= (f ? len - 1 : len); i++)
			{
				cout << s[i];
			}
			cout << s.front() << "ay";
			if(f)
			{
				cout << ".";
			}
		}
	    scanf("%c", &b);
	    if(b == '\r')
	    {
	        b = '\n';
        }
	    printf("%c", b);
	}
	//fclose(stdout);
	return 0;
}

输入样例和与题解代码的对拍都是对的啊

2020/12/1 20:38
加载中...