3423:练72.4 口算练习题
练 72.4 口算练习题
洛谷P1957口算练习题
#include <iostream>
#include <string>
#include <cstring>
#define AUTHOR "HEX9CF"
using namespace std;
const int len = 30;
int main()
{
int t;
cin >> t;
for (int i = 0; i < t; i++)
{
char a[len], b[len], c[len];
char sgn;
long long r, l;
char rStr[len];
scanf("%s", a);
switch (a[0])
{
case 'a':
scanf("%s %s", b, c);
sgn = '+';
break;
case 'b':
scanf("%s %s", b, c);
sgn = '-';
break;
case 'c':
scanf("%s %s", b, c);
sgn = '*';
break;
default:
scanf("%s", c);
strcpy(b, a);
}
switch (sgn)
{
case '+':
r = atoi(b) + atoi(c);
break;
case '-':
r = atoi(b) - atoi(c);
break;
case '*':
r = atoi(b) * atoi(c);
break;
}
// itoa(r, rStr, 10);
snprintf(rStr, sizeof(rStr), "%d", r);
l = 2 + strlen(b) + strlen(c) + strlen(rStr);
printf("%s%c%s=%d\n", b, sgn, c, r);
printf("%d\n", l);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y;
char cc,f,c[20],a[20];
scanf("%d\n",&n);
for(int i=1;i<=n;i++){
fgets(c,15,stdin);
if(c[0]=='a'){
f='a';
sscanf(c,"%c %d %d",&cc,&x,&y);
sprintf(a,"%d+%d=%d",x,y,x+y);
}else if(c[0]=='b'){
f='b';
sscanf(c,"%c %d %d",&cc,&x,&y);
sprintf(a,"%d-%d=%d",x,y,x-y);
}else if(c[0]=='c'){
f='c';
sscanf(c,"%c %d %d",&cc,&x,&y);
sprintf(a,"%d*%d=%d",x,y,x*y);
}else{
sscanf(c,"%d %d",&x,&y);
if(f=='a') sprintf(a,"%d+%d=%d",x,y,x+y);
if(f=='b') sprintf(a,"%d-%d=%d",x,y,x-y);
if(f=='c') sprintf(a,"%d*%d=%d",x,y,x*y);
}
puts(a);
cout<<strlen(a)<<endl;
}
return 0;
}
洛谷、牛客网、AcWing 刷题(python版)
Python 刷题常用语法与数据结构汇总-2022.01.30
python小游戏之一
python小游戏之二
python小游戏之三
python游戏入门书籍推荐
python编程与数学书籍
python编程与数学书籍_python 学数学 mobi 下载-CSDN博客
python习题集整理汇总
第十一届蓝桥杯青少组Python竞赛真题
python算法书籍简介-2022.06.13