如果标题看起来有点不对劲,我提前道歉。我很难决定我应该给它取什么名字。无论如何,基本上我现在所做的完全是处理低级 I/O 的作业。对于我的一项任务,我提供了两个 .txt 文件,一个包含电子邮件地址列表,另一个包含不再出现在电子邮件列表中的成员列表。我要做的是从第二个列表中删除成员的电子邮件。此外,.txt 文件中可能会有一些令人讨厌的惊喜。我必须清理电子邮件并删除电子邮件后任何不需要的标点符号,例如分号、逗号和空格。此外,我需要将所有文本小写。我在解决这个问题的方式不止一种(我不完全确定如何让我的文件在输出中写入我需要的内容),但现在我主要关心的是以正确的顺序输出取消订阅消息。排序似乎不起作用。
以下是一些测试用例:
Test Cases
unsubscribe('Grand Prix Mailing List.txt', ...
'Unsubscribe from Grand Prix.txt')
=> output file named 'Grand Prix Mailing List_updated.txt' that looks
like 'Grand Prix Mailing List_updated_soln.txt'
=> output file named 'Unsubscribe from Grand Prix_messages.txt' that
looks like 'Unsubscribe from Grand Prix_messages_soln.txt'
原始邮件列表
Grand Prix Mailing List:
MPLUMBER3@gatech.edu,
lplumber3@gatech.edu
Ttoadstool3@gatech.edu;
bkoopa3@gatech.edu
ppeach3@gatech.edu,
ydinosaur3@gatech.edu
kBOO3@gatech.edu
WBadguy3@gatech.edu;
FKong3@gatech.edu
dkong3@gatech.edu
dbones3@gatech.edu
不喜欢的人:
MARIO PLUMBER;
bowser koopa
Luigi Plumber,
Donkey Kong
King BOO;
Princess Peach
之后应该是什么样子:
ttoadstool3@gatech.edu
ydinosaur3@gatech.edu
wbadguy3@gatech.edu
fkong3@gatech.edu
dbones3@gatech.edu
我的文件输出:
Mario, you have been unsubscribed from the Grand Prix mailing list.
Luigi, you have been unsubscribed from the Grand Prix mailing list.
Bowser, you have been unsubscribed from the Grand Prix mailing list.
Princess, you have been unsubscribed from the Grand Prix mailing list.
King, you have been unsubscribed from the Grand Prix mailing list.
Donkey, you have been unsubscribed from the Grand Prix mailing list.
因此,Amro 提供了一个解决方案,尽管它比我现在所知道的要高一点。我现在的主要问题是,当我输出退订消息时,我需要它与原始电子邮件列表的顺序相同。例如,当 Bowser 在 Luigi 之前在投诉名单上时,在取消订阅消息中,Luigi 需要在他之前出现。
这是我的原始代码:
function[] = unsubscribe(email_ids, member_emails)
Old_list = fopen(email_ids, 'r'); %// opens my email list
Old_Members = fopen(member_emails, 'r'); %// Opens up the names of people who want to unsubscribe
emails = fgets(Old_list); %// Reads first line of emails
member_emails = [member_emails]; %// Creates an array to populate
while ischar(emails) %// Starts my while loop
%// Pulls out a line in the email
emails = fgets(Old_list);
%// Quits when it sees this jerk
if emails == -1
break;
end
%// I go in to clean stuff up here, but it doesn't do any of it. It's still in the while loop though, so I am not sure where the error is
proper_emails = lower(member_emails); %// This is supposed to lowercase the emails, but it's not working
unwanted = findstr(member_emails, ' ,;');
member_emails(unwanted) = '';
member_emails = [member_emails, emails];
end
while ischar(Old_Members) %// Does the same for the members who want to unsubscribe
names = fgetl(member_emails);
if emails == -1
break
end
proper_emails = lower(names); %// Lowercases everything
unwanted = findstr(names, ' ,;');
names(unwanted) = '';
end
Complainers = find(emails);
New_List = fopen('Test2', 'w'); %// Creates a file to be written to
fprintf(New_List, '%s', member_emails); %// Writes to it
Sorry_Message = fopen('Test.txt', 'w');
fprintf(Sorry_Message, '%s', Complainers);
%// Had an issue with these, so I commented them out temporarily
%// fclose(New_List);
%// fclose(Sorry_Message);
%// fclose(email_ids);
%// fclose(members);
end