刚才做OJ上一道题,一直是Wrong answer,求助。

LEE_coding 2009-02-06 08:20:26
这是题目:
Description
The blonde Angela has a new whim: internet chats. Of course, as any blonde, she writes her messages using the upper case. You are the moderator of Angela's favorite chat and you're fed up with her upper-case messages. The problem is that Angela does not respond to your warnings. You decided to write a simple antiCAPS corrector, which would make Angela's messages readable.

The correction rules are very simple:

Sentences in a message consist of words, spaces and punctuation marks.
Words consist of English letters.
Sentences end with a full stop, exclamation mark, or question mark.
The first word of each sentence must start with a capital letter, and all other letters of the sentence must be lowercase.


Input
You are given Angela's message, which consists of uppercase English letters, spaces, line breaks and punctuation marks: full stops, commas, dashes, colons, exclamation and question marks. Total length of message is not exceeding 10000 symbols.



Output
Output the corrected message.



Sample Input
HI, THERE!
HOW DID YOU KNOW I AM A BLONDE?



Sample Output
Hi, there!
How did you know i am a blonde?

这是我实现的代码,我自己运行测试了很多数据都没问题,但提交就是wrong,请大家看看有什么不妥。
#include <iostream>
#include <cctype>
#include <string>
using namespace std;

int main()
{
char input[10000];
cin.get(input,10000,EOF);

input[0]=toupper(input[0]);

for(int i=1;input[i]!=EOF;++i)
{
if (input[i]=='!'||input[i]=='.'||input[i]=='?')
{
do {
i++;
} while(!isalpha(input[i]));
input[i]=toupper(input[i]);
}
else
{
input[i]=tolower(input[i]);
}
}
cout<<input<<endl;

return 0;
}
这是OJ后台给出的信息:
Test # 1..... Accepted
Use Time 0ms, Use Memory 56KB
Test # 2..... Accepted
Use Time 0ms, Use Memory 56KB
Test # 3..... Accepted
Use Time 4ms, Use Memory 56KB
Test # 4..... Accepted
Use Time 0ms, Use Memory 60KB
Test # 5..... Accepted
Use Time 4ms, Use Memory 56KB
Test # 6..... Wrong Answer
Use Time 0ms, Use Memory 56KB

The Result is Wrong Answer.
Terminated On Test #6
Use Time 8ms, Use Memory 60KB
...全文
499 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
LEE_coding 2009-02-06
  • 打赏
  • 举报
回复
问题解决,就是因为第一个字母没解决好,谢谢楼上
butchroller 2009-02-06
  • 打赏
  • 举报
回复
input:
------THIS IS A TEST. HOW ARE YOU? OK!!!
output:
------this is a test. How are you? Ok!!!

你再试试。
码农自来也 2009-02-06
  • 打赏
  • 举报
回复
把数组再开大点,题目只是说不超过10000,并不代表不会等于的
LEE_coding 2009-02-06
  • 打赏
  • 举报
回复
总是在测试第6步通不过,你可以把这代码在自己机器上编译试试,我运行了都没问题,也不清楚是什么条件导致错误了。
LEE_coding 2009-02-06
  • 打赏
  • 举报
回复
不一定啊,但如果不是字母TOUPPER是不会转换的啊
butchroller 2009-02-06
  • 打赏
  • 举报
回复
第一个肯定是字母吗?
LEE_coding 2009-02-06
  • 打赏
  • 举报
回复
就是第一个字母保证是大写
butchroller 2009-02-06
  • 打赏
  • 举报
回复
input[0]=toupper(input[0]);
----------------------
?

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧