题目的url:http://acm.hdu.edu.cn/showproblem.php?pid=1736
这道题要注意几点:
1.怎样输出一个汉字。
2.源串里的双引号一个是中文的,一个是英文的。
3.另外,输入是多行 的,不是单行的。
我的AC代码:
#include<iostream>
#include<string.h>
using namespace std;
const int Max = 10000;
char str[Max];
char comma[] = ",";
char period[] = "。";
char exclamation[] = "!";
char leftQuotation[] = "“";
char rightQuotation[] = "”";
char leftBook[] = "《";
char rightBook[] = "》";
char question[] = "?";
int main()
{
//gets(str);
int pos = 0;
bool leftPrinted = false;
while(cin.getline(str, 10000))
{
int len = strlen(str);
char chWord[3];
for(int i=0; i<len; i++)
{
if(str[i] == ',') printf("%s", comma);
else if(str[i] == '.') printf("%s", period);
else if(str[i] == '!') printf("%s", exclamation);
else if(str[i] == '<' && str[i+1] == '<')
{
printf("%s", leftBook);
i ++;
}
else if(str[i] == '>' && str[i+1] == '>')
{
printf("%s", rightBook);
i ++;
}
else if(str[i] == '?') printf("%s", question);
else if(str[i] == '"')
{
if(!leftPrinted)
{
printf("%s", leftQuotation);
leftPrinted = true;
}
else
{
printf("%s", rightQuotation);
leftPrinted = false;
}
}
else if(str[i] < 0)
{
chWord[pos++] = str[i];
if(pos == 2)
{
chWord[pos] = '\0';
printf("%s", chWord);
pos = 0;
if(strcmp(chWord, leftQuotation) == 0) leftPrinted = true;
if(strcmp(chWord, rightQuotation) == 0) leftPrinted = false;
}
}
else
{
printf("%c", str[i]);
}
}
printf("\n");
}
system("pause");
return 0;
}