【题目描述】
给定一个单词,如果该单词以er、ly或者ing后缀结尾, 则删除该后缀(题目保证删除后缀后的单词长度不为0), 否则不进行任何操作。
【输入】
输入一行,包含一个单词(单词中间没有空格,每个单词最大长度为32)。
【输出】
输出按照题目要求处理后的单词。
【输入样例】
referer
【输出样例】
refer
【源代码】
#include <iostream>
using namespace std;char word[32] = {};
int main()
{cin >> word;int length = strlen(word);if (word[length - 1] == 'r') // er结尾;{if (word[length - 2] == 'e'){word[length - 1] = 0;word[length - 2] = 0;}}else if (word[length - 1] == 'y') // ly结尾;{if (word[length - 2] == 'l'){word[length - 1] = 0;word[length - 2] = 0;}}else if (word[length - 1] == 'g') // ing结尾;{if (word[length - 2] == 'n'){if (word[length - 3] == 'i'){word[length - 1] = 0;word[length - 2] = 0;word[length - 3] = 0;}}}for (int i = 0; i < length; i++){if (word[i] != 0){cout << word[i];}}cout << endl;return 0;
}