小白书上的代码相对来说简单一些,另外注意TeX格式的左双引号为··
这里先贴上自己的代码:
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<cassert>
using namespace std;
char *s="`1234567890-=QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,./";
#define LL long long
int main()
{
char c;
int num=1;
while((c=getchar())!=EOF)
{
if(c=='"')
{
if(num%2)
cout<<"``";
else
cout<<""";
num++;
}
else
cout<<c;
}
return 0;
}
然后是小白书的代码,主要注意他这里设置q和c的定义与输入输出的简洁性以及直接使用条件三段式输出的简洁性:
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<cassert>
using namespace std;
char *s="`1234567890-=QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,./";
#define LL long long
int main()
{
int c,q=1;
while((c=getchar())!=EOF)
{
if(c =='"')
{
printf("%s",q ? "``":"''");
q=!q;
}
}
return 0;
}
本文深入剖析了通过字符处理和输出优化来提升代码效率的策略,通过对比小白书提供的代码示例,展示了如何利用简洁的条件三段式输出和输入读取方式来简化程序实现。重点讲解了字符识别、判断和输出的优化方法,旨在提高编程实践能力。
1079

被折叠的 条评论
为什么被折叠?



