本文主要是介绍第八届湘潭大学程序设计比赛 A Love Letter,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A Love Letter | ||
Accepted : 58 | Submit : 152 | |
Time Limit : 1000 MS | Memory Limit : 65536 KB |
题目描述CodeMonkey终于下定决心用情书的方式向心爱的女神表白,当他历经几天几夜写完之后才知道女神有很多不喜欢的词,所以他不得不有把这些词删掉。例如:原文是:ILOVEYOU,女神不喜欢的词是‘LV’,‘O’那么最终情书要改成IEYU。现在已知女生不喜欢的词的集合S,CodeMonkey想知道刚写的情书会改成什么样?S={“HATE”,“SHIT”,“LV”,“O”,“FUCK”,“UGLY”,“MM”} 输入多样例输入,每个样例输入一行情书原文,原文只包含大写英文字母,原文长度不超过1000 输出对于每个样例,若是情书被删完则输出一行“LOSER”,否则输出情书的剩余内容 样例输入ILOVEYOU MM 样例输出IEYU LOSER |
很简单的水题,比赛时却没做出来,贴出来警示自己
代码:
#include <string.h>
#include <stdio.h>
char a[1010];
int len;
int act()
{int ok = 0;for (int i = 0; i < len; i++){if (i + 4 <= len){if (a[i] == 'H'&&a[i + 1] == 'A'&&a[i + 2] == 'T' && a[i + 3] == 'E'){for (; i < len; i++)a[i] = a[i + 4];len = len - 4;ok = 1;}if (a[i] == 'S'&&a[i + 1] == 'H'&&a[i + 2] == 'I' && a[i + 3] == 'T'){for (; i < len; i++)a[i] = a[i + 4];len = len - 4;ok = 1;}if (a[i] == 'F'&&a[i + 1] == 'U'&&a[i + 2] == 'C' && a[i + 3] == 'K'){for (; i < len; i++)a[i] = a[i + 4];len = len - 4;ok = 1;}if (a[i] == 'U'&&a[i + 1] == 'G'&&a[i + 2] == 'L' && a[i + 3] == 'Y'){for (; i < len; i++)a[i] = a[i + 4];len = len - 4;ok = 1;}}if (i + 2 <= len){if (a[i] == 'L'&&a[i + 1] == 'V'){for (; i < len; i++)a[i] = a[i + 2];len = len - 2;ok = 1;}if (a[i] == 'M'&&a[i + 1] == 'M'){for (; i < len; i++)a[i] = a[i + 2];len = len - 2;ok = 1;}}if (i + 1 <= len){if (a[i] == 'O'){for (; i < len; i++)a[i] = a[i + 1];len = len - 1;ok = 1;}}}return ok;
}
int main()
{while (scanf("%s", a) != EOF){len = strlen(a);while (act() && len > 0){}if (len == 0)puts("LOSER");else{for (int i = 0; i < len; i++)printf("%c", a[i]);printf("\n");}}return 0;
}
这篇关于第八届湘潭大学程序设计比赛 A Love Letter的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!