如何在不改变代码思路的情况下,用sprintf输出字符长度

P1957 口算练习题

Lmm_a @ 2021-07-15 15:26:02

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int a[51],b[51],d[51];char c[51];
int main()
{
    int i,n,d,p,q;string x,y;
    string s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>c[i]>>a[i]>>b[i];
    }
    for(i=1;i<=n;i++)
    {
           if(c[i]=='a')cout<<a[i]<<"+"<<b[i]<<"="<<a[i]+b[i]<<endl;
    else    if(c[i]=='b')cout<<a[i]<<"-"<<b[i]<<"="<<a[i]-b[i]<<endl;
    else    if(c[i]=='c')cout<<a[i]<<"*"<<b[i]<<"="<<a[i]*b[i]<<endl;
    else   if(c[i-1]=='a')cout<<a[i]<<"+"<<b[i]<<"="<<a[i]+b[i]<<endl;
    else    if(c[i-1]=='b')cout<<a[i]<<"-"<<b[i]<<"="<<a[i]-b[i]<<endl;
    else    if(c[i-1]=='c')cout<<a[i]<<"*"<<b[i]<<"="<<a[i]*b[i]<<endl;
    }
    return 0;
}

|