花里胡哨的代用记号与三标符

紫陰花

2019-08-23 10:15:39

科技·工程

前言:

作者完全是出于兴趣瞎写了一篇文章投稿的,没想到真发表了。

本文几乎毫无学术价值,请勿引战。

广告:洛谷定律&名词 关于她们......

关于代用记号

是不是&,|,^什么的都用习惯了?

代用记号让你感叹道还是原来的好新的太长了记都记不住

喏,它们就长这个亚子:

and
and_eq
or
or_eq
xor
xor_eq
not
not_eq
bitand
bitor
compl
<%
%>
<:
:>
%:
%:%:

都什么鬼东西啊!

但有没有一种似曾相识的感觉?

英文学得如何啊?

这些新代用记号能与原有的操作符完美替换,直接改不会有任何问题

我觉得这种代用记号的好处在于可读性加强了,毕竟英语大家都能看懂,一些奇奇怪怪的符号也只有OIer能出手了(那后面六个……)

and

表示逻辑与操作,等价于&&操作符,可直接替换

int n,m,k;
scanf("%d%d%d",&n,&m,&k);
if(n==m and m==k)//将这里的and改为&&也可通过
    printf("Yes\n");
else
    printf("No\n");

and_eq

表示相与并赋值,等价于&=操作符(不常用?)

char n,m;
cin>>n>>m;
n and_eq m;
cout<<n;

or

表示逻辑或,等价于||操作符

int n,m,k;
scanf("%d%d%d",&n,&m,&k);
if(n==m or m==k)
    printf("Yes\n");
else
    printf("No\n");

or_eq

表示相或并赋值,等价于|=操作符(不常用?)

char n,m;
cin>>n>>m;
n or_eq m;
cout<<n;

xor

表示逻辑异或,等价于^操作符

int a,b;
scanf("%d%d",&a,&b);
printf("%d",int(a xor b));

xor_eq

表示相异或并赋值,等价于^=操作符

int a,b;
scanf("%d%d",&a,&b);
a xor_eq b xor_eq a xor_eq b; //等价于a^=b^=a^=b; 
//这段代码相当于swap(a,b);
printf("%d %d",a,b);

not

表示逻辑非, 等价于!操作符

srand(time(NULL));
queue<int> q;
int b=rand()%32+1;
for(int i=1;i<=b;i++)
    q.push(rand()%32);
while(not(q.empty()))
{
    printf("%d\n",q.front());
    q.pop();
}

not_eq

等价于!=操作符

int a,b;
scanf("%d%d",&a,&b);
if(a not_eq b)
    printf("Yes");
else
    printf("No");

bitand, bitor

and,or类似,不过是按位操作,bitand等价于&,bitor等价于|

?)断词:bit andbit or

compl

按位取反 等价于~操作符

那以后打删除线时是不是要complcompl内容complcompl

int a;
scanf("%d",&a);
printf("%d",int(compl a));

重头戏要来了!

<%,%>

相当于大括号{}

越来越诡异了

#include<bits/stdc++.h>
using namespace std;
int main()
<%

%>

<:,:>

相当于中括号[,]

太诡异了吧

#include<bits/stdc++.h>
using namespace std;
int x<:50:>;
int main()
{
    cin>>x<:1:>;
    cout<<x<:1:>;
}

%:,%:%:

相当于###

%:include<bits/stdc++.h>
using namespace std;
%:define maxx 500
%:define F(i,a,b) for(register int i=a,i%:%:_end=b;i<=i%:%:_end;++i)//用##卡常?
int f[maxx];
int main()
{

}

一些摘录:

当分析器遇到字符序列<::,且后继字符既非:亦非>时,<被当做预处理记号本身,而非代用记号<:。从而std::vector<::std::string>不会被错误地处理成std::vector[:std::string>。(C++11起)

注解 字符&!ISO-646下不变,但仍然为使用这些字符的记号提供了代用写法,以便能够适应更加受限的历史字符集。

没有相等运算符的代用拼写==eq),因为字符=已在所有受支持字符集中存在。

C的兼容性 C编程语言中,同样的单词作为宏定义于包含文件<iso646.h>之中。因为C++中它们内建于语言,故<iso646.h>C++版本还有<ciso646>不定义任何内容。

另附:各种代用记号的综合使用

P1100:

%:include<bits/stdc++.h>
%:define maxn 50
char x<:maxn:>;
int main()
<%
    long long a,ans=0,b;
    int i;
    scanf("%lld",&a);
    for(i=0;i<32;i++)
        x<:i:>=char(a%2+'0'),a/=2;
    for(i=0;i<16;i++)
        x<:i:> xor_eq x<:i+16:> xor_eq x<:i:> xor_eq x<:i+16:>;
    for(i=0,b=1;i<32;i++,b*=2)
        ans+=int(x<:i:>-'0')*b;
    printf("%lld",ans);
%> 
//写的我头都晕了……

代用记号:简易对照表

and &&
and_eq &=
or ||
or_eq |=
xor ^
xor_eq ^=
not !
not_eq !=
bitand &
bitor |
compl ~
<% {
%> }
<: [
:> ]
%: #
%:%: ##

关于三标符:

感觉没有用,按照cppreference.com上面的说法,这东西在C++17时被移除了 但是还是要看一下的 为了凑篇幅

对于这些东西不详细描述,直接给出对应表:

??< {
??> }
??( [
??) ]
??= #
??/ \
??' ^
??! |
??- ~

摘录:

因为三标符的处理非常早,所以如// Will the next line be executed?????/这样的注释实际上会注释掉下一行,而如"Enter date ??/??/??"这样的字符串字面量将被分析为"Enter date \\??"

总结:这些东西没用

参考文献:

1.C++11新特性之and, and_eq, or, or_eq, xor, xor_eq, not, not_eq操作符

2.代用运算符表示