题目链接:P1957 口算练习题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
sscanf(str,"%d",&n) 其实就是把str的内容以"%d"的格式写入到n中(从左到右)
同理 sprintf(str,"%d",n)就是把n以"%d"的格式写入到str (从右到左)
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; char s[N]; char box; int n,a,b,c,d; int main() { cin>>n; while(n--) { cin>>s; if(s[0]=='a'||s[0]!='b'||s[0]!='c') box=s[0],cin>>c>>d; else sscanf(s,"%d",&c),cin>>d;//s是字符串,然后变成%d类型,储存给c memset(s,0,sizeof s); if(box=='a') sprintf(s,"%d+%d=%d",c,d,c+d); else if(box=='b') sprintf(s,"%d-%d=%d",c,d,c-d); else if(box=='c') sprintf(s,"%d*%d=%d",c,d,c*d); cout<<s<<endl<<strlen(s)<<endl; } return 0; }
标签:box,大法,sscanf,int,cin,sprintf,str From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17471279.html