社区讨论

64分求调

P1022[NOIP 2000 普及组] 计算器的改良参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@mm032tsr
此快照首次捕获于
2026/02/24 12:06
2 周前
此快照最后确认于
2026/02/25 21:25
2 周前
查看原帖
WA on #3 #6:
CPP
#include<bits/stdc++.h>
using namespace std;
string s,s1,s2;
char ch;
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    getline(cin,s);
    s1 = s.substr(0,s.find('='));
    s2 = s.substr(s.find('=')+1,s.length());
    // 解析s1
    int c=0,n=0,x=0,y=0;  // 0=+ 1=-
    for(int i=0;i<s1.length();i++){
        if(s1[i]>='0' && s1[i]<='9'){
            n = n*10+int(s1[i]-'0');
        }
        else if(s1[i]>='a' && s1[i]<='z'){
            ch = s1[i];
            if(c==0){
                x += n;
            }
            else{
                x -= n;
            }
            n = 0;
        }
        else{
            if(n!=0){
                if(c==1){
                    y -= n;
                }
                else{
                    y += n;
                }
                n = 0;
            }
            if(s1[i]=='-'){
                c = 1;
            }
            else{
                c = 0;
            }
        }
    }
    if(n!=0){
        if(c==0){
            y += n;
        }
        else{
            y -= n;
        }
    }
    // 解析s2
    int c2=0,n2=0,x2=0,y2=0;  // 0=+ 1=-
    for(int i=0;i<s2.length();i++){
        if(s2[i]>='0' && s2[i]<='9'){
            n2 = n2*10+int(s2[i]-'0');
        }
        else if(s2[i]>='a' && s2[i]<='z'){
            if(c2==0){
                x2 += n2;
            }
            else{
                x2 -= n2;
            }
            n2 = 0;
        }
        else{
            if(n2!=0){
                if(c2==1){
                    y2 -= n2;
                }
                else{
                    y2 += n2;
                }
                n2 = 0;
            }
            if(s2[i]=='-'){
                c2 = 1;
            }
            else{
                c2 = 0;
            }
        }
    }
    if(n2!=0){
        if(c2==0){
            y2 += n2;
        }
        else{
            y2 -= n2;
        }
    }
    x -= x2;
    y2 -= y;
    cout<<ch;
    printf("=%.3lf",y2*1.0/x);
    
    return 0;
}
帮调必关,谢谢。

回复

1 条回复,欢迎继续交流。

正在加载回复...