Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ch3/UVa10082.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ char s[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
int main() {
int i, c;
while((c = getchar()) != EOF) {
for (i=1; s[i] && s[i]!=c; i++); // 找错位之后的字符在常量表中的位置
for (i=1; s[i]!=0 && s[i]!=c; i++); // 找错位之后的字符在常量表中的位置

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在C的逻辑判断,非0值为真,所以这边if(s[i])等价if(s[i] != 0),同理if(!x)等价if(x==0)
不过用if(s[i] != 0)更直观

if (s[i]) putchar(s[i-1]); // 如果找到,则输出它的前一个字符
else putchar(c);
}
Expand Down