Greeper @ 2024-07-25 15:20:51
刚发完函数就WA
#include<bits/stdc++.h>
using namespace std;
int n;
string a,b,c,d;
char f;
int math(string a)
{
int l=a.size();
int x=0;
for(int i=0;i<l;i++)
{
x*=10;
x+=int(a[i]-'0');
}
return x;
}
string str(int a)
{
string y,x;
while(a)
{
y+=char(a%10+'0');
a/=10;
}
for(int i=y.size()-1;i>=0;i--)
{
x+=y[i];
}
return x;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
if(a[0]>='a'&&a[0]<='c')
{
f=a[0];
cin>>b>>c;
}
else
{
b=a;
cin>>c;
}
if(f=='a')
{
cout<<b<<'+'<<c<<'='<<math(b)+math(c)<<endl;
cout<<b.size()+c.size()+2+str(math(b)+math(c)).size()<<endl;
}
if(f=='b')
{
cout<<b<<'-'<<c<<'='<<math(b)-math(c)<<endl;
cout<<b.size()+c.size()+2+str(math(b)-math(c)).size()<<endl;
}
if(f=='c')
{
cout<<b<<'+'<<c<<'='<<math(b)*math(c)<<endl;
cout<<b.size()+c.size()+2+str(math(b)*math(c)).size()<<endl;
}
}
return 0;
}
by cute_ @ 2024-07-25 15:27:22
稍等 我看看
by cute_ @ 2024-07-25 15:27:56
看了看题 你这也太复杂了吧。。。。
by cute_ @ 2024-07-25 16:13:00
#include<bits/stdc++.h>
using namespace std;
int n;
string x;
string x1;
int a;
int b;
int c;
int w(int k){
int ans=0;
if(k<0){
k*=-1;
ans++;
}
while(k){
ans++;
k/=10;
}
return ans;
}
int do_c(){
c=0;
for(int i=0;i<=x.size()-1;i++){
c*=10;
c+=x[i]-48;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
x1=x;
cin>>x;
if(x[0]=='a'){
cin>>a;
cin>>b;
cout<<a<<'+'<<b<<'='<<a+b<<endl;
cout<<w(a)+w(b)+w(a+b)+2<<endl;
}
else if(x[0]=='b'){
cin>>a;
cin>>b;
cout<<a<<'-'<<b<<'='<<a-b<<endl;
cout<<w(a)+w(b)+w(a-b)+2<<endl;
}
else if(x[0]=='c'){
cin>>a;
cin>>b;
cout<<a<<'*'<<b<<'='<<a*b<<endl;
cout<<w(a)+w(b)+w(a*b)+2<<endl;
}
else{
do_c();
if(x1[0]=='a'){
cin>>b;
cout<<c<<'+'<<b<<'='<<c+b<<endl;
cout<<w(c)+w(b)+w(c+b)+2<<endl;
}
if(x1[0]=='b'){
cin>>b;
cout<<c<<'-'<<b<<'='<<c-b<<endl;
cout<<w(c)+w(b)+w(c-b)+2<<endl;
}
if(x1[0]=='c'){
cin>>b;
cout<<c<<'*'<<b<<'='<<c*b<<endl;
cout<<w(c)+w(b)+w(c*b)+2<<endl;
}
}
}
}
70行。。我也就40分
by cute_ @ 2024-07-25 16:15:30
哦哦 我知道哪出问题了
by cute_ @ 2024-07-25 16:25:05
#include<bits/stdc++.h>
using namespace std;
int n;
string x;
string x1;
int a;
int b;
int c;
int w(int k){
int ans=0;
if(k==0) return 1;
if(k<0){
k*=-1;
ans++;
}
while(k){
ans++;
k/=10;
}
return ans;
}
int do_c(){
c=0;
if(x[0]=='-'){
for(int i=1;i<=x.size()-1;i++){
c*=10;
c+=x[i]-48;
}
c=-c;
}
else{
for(int i=0;i<=x.size()-1;i++){
c*=10;
c+=x[i]-48;
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
x1=x;
cin>>x;
if(x[0]=='a'){
cin>>a;
cin>>b;
cout<<a<<'+'<<b<<'='<<a+b<<endl;
cout<<w(a)+w(b)+w(a+b)+2<<endl;
}
else if(x[0]=='b'){
cin>>a;
cin>>b;
cout<<a<<'-'<<b<<'='<<a-b<<endl;
cout<<w(a)+w(b)+w(a-b)+2<<endl;
}
else if(x[0]=='c'){
cin>>a;
cin>>b;
cout<<a<<'*'<<b<<'='<<a*b<<endl;
cout<<w(a)+w(b)+w(a*b)+2<<endl;
}
else{
do_c();
if(x1[0]=='a'){
cin>>b;
cout<<c<<'+'<<b<<'='<<c+b<<endl;
cout<<w(c)+w(b)+w(c+b)+2<<endl;
}
if(x1[0]=='b'){
cin>>b;
cout<<c<<'-'<<b<<'='<<c-b<<endl;
cout<<w(c)+w(b)+w(c-b)+2<<endl;
}
if(x1[0]=='c'){
cin>>b;
cout<<c<<'*'<<b<<'='<<c*b<<endl;
cout<<w(c)+w(b)+w(c*b)+2<<endl;
}
}
}
}
60分,评测结果
by cute_ @ 2024-07-25 16:29:58
#include<bits/stdc++.h>
using namespace std;
int n;
string x;
string x1;
int a;
int b;
int c;
int w(int k){
int ans=0;
if(k==0) return 1;
if(k<0){
k*=-1;
ans++;
}
while(k){
ans++;
k/=10;
}
return ans;
}
int do_c(){
c=0;
if(x[0]=='-'){
for(int i=1;i<=x.size()-1;i++){
c*=10;
c+=x[i]-48;
}
c=-c;
}
else{
for(int i=0;i<=x.size()-1;i++){
c*=10;
c+=x[i]-48;
}
}
return 0;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
x1=x;
cin>>x;
if(x[0]=='a'){
cin>>a;
cin>>b;
cout<<a<<'+'<<b<<'='<<a+b<<endl;
cout<<w(a)+w(b)+w(a+b)+2<<endl;
}
else if(x[0]=='b'){
cin>>a;
cin>>b;
cout<<a<<'-'<<b<<'='<<a-b<<endl;
cout<<w(a)+w(b)+w(a-b)+2<<endl;
}
else if(x[0]=='c'){
cin>>a;
cin>>b;
cout<<a<<'*'<<b<<'='<<a*b<<endl;
cout<<w(a)+w(b)+w(a*b)+2<<endl;
}
else{
do_c();
if(x1[0]=='a'){
cin>>b;
cout<<c<<'+'<<b<<'='<<c+b<<endl;
cout<<w(c)+w(b)+w(c+b)+2<<endl;
}
if(x1[0]=='b'){
cin>>b;
cout<<c<<'-'<<b<<'='<<c-b<<endl;
cout<<w(c)+w(b)+w(c-b)+2<<endl;
}
if(x1[0]=='c'){
cin>>b;
cout<<c<<'*'<<b<<'='<<c*b<<endl;
cout<<w(c)+w(b)+w(c*b)+2<<endl;
}
}
}
}
加了return 0,70分
by cute_ @ 2024-07-25 16:36:42
#include<bits/stdc++.h>
using namespace std;
int n;
string x;
string x1;
int a;
int b;
int c;
int f;
int w(int k){
int ans=0;
if(k==0) return 1;
if(k<0){
k*=-1;
ans++;
}
while(k){
ans++;
k/=10;
}
return ans;
}
int do_c(){
c=0;
if(x[0]=='-'){
for(int i=1;i<=x.size()-1;i++){
c*=10;
c+=x[i]-48;
}
c=-c;
}
else{
for(int i=0;i<=x.size()-1;i++){
c*=10;
c+=x[i]-48;
}
}
return 0;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
if(f==0) x1=x;
cin>>x;
if(x[0]=='a'){
f=0;
cin>>a;
cin>>b;
cout<<a<<'+'<<b<<'='<<a+b<<endl;
cout<<w(a)+w(b)+w(a+b)+2<<endl;
}
else if(x[0]=='b'){
f=0;
cin>>a;
cin>>b;
cout<<a<<'-'<<b<<'='<<a-b<<endl;
cout<<w(a)+w(b)+w(a-b)+2<<endl;
}
else if(x[0]=='c'){
f=0;
cin>>a;
cin>>b;
cout<<a<<'*'<<b<<'='<<a*b<<endl;
cout<<w(a)+w(b)+w(a*b)+2<<endl;
}
else{
do_c();
if(x1[0]=='a'){
f=1;
cin>>b;
cout<<c<<'+'<<b<<'='<<c+b<<endl;
cout<<w(c)+w(b)+w(c+b)+2<<endl;
}
if(x1[0]=='b'){
f=1;
cin>>b;
cout<<c<<'-'<<b<<'='<<c-b<<endl;
cout<<w(c)+w(b)+w(c-b)+2<<endl;
}
if(x1[0]=='c'){
f=1;
cin>>b;
cout<<c<<'*'<<b<<'='<<c*b<<endl;
cout<<w(c)+w(b)+w(c*b)+2<<endl;
}
}
}
}
我草 88行终于ac了
by Greeper @ 2024-07-26 15:02:51
@cute_
#include<bits/stdc++.h>
using namespace std;
int n;
string a;
int b,c;
char f;
int math(string a)
{
int l=a.size();
int x=0;
for(int i=0;i<l;i++)
{
x*=10;
x+=int(a[i]-'0');
}
return x;
}
int intlen(int a)
{
string x;
while(a)
{
x+=char(a%10+'0');
a/=10;
}
return x.size();
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
if(a[0]>='a'&&a[0]<='c')
{
f=a[0];
cin>>b>>c;
}
else
{
b=math(a);
cin>>c;
}
if(f=='a')
{
cout<<b<<'+'<<c<<'='<<b+c<<endl;
cout<<intlen(b)+intlen(c)+intlen(b+c)+2<<endl;
}
if(f=='b')
{
cout<<b<<'-'<<c<<'='<<b-c<<endl;
cout<<intlen(b)+intlen(c)+intlen(b-c)+2<<endl;
}
if(f=='c')
{
cout<<b<<'+'<<c<<'='<<b*c<<endl;
cout<<intlen(b)+intlen(c)+intlen(b*c)+2<<endl;
}
}
return 0;
}
还10分
by cute_ @ 2024-07-26 15:43:56
@Greeper 6 你看一下我ac的,要判负数,要判类型 符号 string转int等等
by Greeper @ 2024-07-27 14:08:53
@cute_ 说实话,没明白T_T\
无奈的蒟蒻\
什么意思,什么类型?\
题里好像说了没有负\
还有,以我的(没用的)知识水平,没看懂你的do_c是干什么的(T_T)