답안 #884588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884588 2023-12-07T17:45:32 Z kokoue 홀-짝 수열 (IZhO11_oddeven) C++14
컴파일 오류
0 ms 0 KB
void clean(string &s)
{
    int sz=s.size();
    int i=0;
    while(i<sz&&s[i]=='0')i++;
    if(i==sz) s="0";
    else
    {
        s=s.substr(i,sz-i);
    }
}
int equalSize(string &s1,string &s2)
{
    int sz1=s1.size(),sz2=s2.size();
    int max_sz=sz1;
    if(sz1<sz2)
    {
        int diff=sz2-sz1;
        max_sz=sz2;
        for(int i=0;i<diff;i++)
        {
            s1='0'+s1;
        }
    }
    if(sz2<sz1)
    {
        int diff=sz1-sz2;
        max_sz=sz1;
        for(int i=0;i<diff;i++)
        {
            s2='0'+s2;
        }
    }
    return max_sz;
}
string sumbig(string s1,string s2)
{

    int summ,rem=0;
    char c;
    string result="";
    int max_sz=equalSize(s1,s2);
    for(int i=max_sz-1;i>=0;i--)
    {
        summ=(s1[i]-'0')+(s2[i]-'0')+rem;
        rem=summ/10;
        c=summ%10+'0';
        result=c+result;
    }
    if(rem) result='1'+result;
    return result;
}
string diff(string s1,string s2)
{
    int sz1=s1.size(),sz2=s2.size(),lamp,rem=0,diff;
    string result;
    char c;
    if((sz2>sz1) || (sz1==sz2 && s1<s2))
    {
        swap(s1,s2);
        lamp=1;
    }
    int max_sz=equalSize(s1,s2);
    for(int i=max_sz-1;i>=0;i--)
    {
        diff=(s1[i]-'0'-rem)-(s2[i]-'0');
        rem=0;
        if(diff<0){diff+=10;rem=1;}
        c=diff+'0';
        result=c+result;
    }
    clean(result);
    return result;
}
string multy(string s,int dig)
{
    int sz,max_sz,mult,rem=0;
    sz=s.size();
    string result;
    string c;
    if(dig)
    {
        for(int i=sz-1;i>=0;i--)
        {
            mult=(s[i]-'0')*dig+rem;
            rem=mult/10;
            c=mult%10+'0';
            result=c+result;
        }
        if(rem>0){c=rem+'0';result=c+result;}
    }
    else result="0";
    return result;
}
bool cmpBig(string s1,string s2)
{
    int sz1=s1.size(),sz2=s2.size();
    if(sz1>sz2) return true;
    if(sz1==sz2)
    {
        if(s1>s2) return true;
    }
    return false;
}
bool cmpBig2(string s1,string s2)
{
    int sz1=s1.size(),sz2=s2.size();
    if(sz1>sz2) return true;
    if(sz1==sz2)
    {
        if(s1>s2) return true;
        if(s1==s2) return true;
    }
    return false;
}

Compilation message

oddeven.cpp:1:6: error: variable or field 'clean' declared void
    1 | void clean(string &s)
      |      ^~~~~
oddeven.cpp:1:12: error: 'string' was not declared in this scope
    1 | void clean(string &s)
      |            ^~~~~~
oddeven.cpp:1:20: error: 's' was not declared in this scope
    1 | void clean(string &s)
      |                    ^
oddeven.cpp:12:15: error: 'string' was not declared in this scope
   12 | int equalSize(string &s1,string &s2)
      |               ^~~~~~
oddeven.cpp:12:23: error: 's1' was not declared in this scope
   12 | int equalSize(string &s1,string &s2)
      |                       ^~
oddeven.cpp:12:26: error: 'string' was not declared in this scope
   12 | int equalSize(string &s1,string &s2)
      |                          ^~~~~~
oddeven.cpp:12:34: error: 's2' was not declared in this scope
   12 | int equalSize(string &s1,string &s2)
      |                                  ^~
oddeven.cpp:12:36: error: expression list treated as compound expression in initializer [-fpermissive]
   12 | int equalSize(string &s1,string &s2)
      |                                    ^
oddeven.cpp:36:1: error: 'string' does not name a type
   36 | string sumbig(string s1,string s2)
      | ^~~~~~
oddeven.cpp:53:1: error: 'string' does not name a type
   53 | string diff(string s1,string s2)
      | ^~~~~~
oddeven.cpp:75:1: error: 'string' does not name a type
   75 | string multy(string s,int dig)
      | ^~~~~~
oddeven.cpp:95:13: error: 'string' was not declared in this scope
   95 | bool cmpBig(string s1,string s2)
      |             ^~~~~~
oddeven.cpp:95:23: error: 'string' was not declared in this scope
   95 | bool cmpBig(string s1,string s2)
      |                       ^~~~~~
oddeven.cpp:95:32: error: expression list treated as compound expression in initializer [-fpermissive]
   95 | bool cmpBig(string s1,string s2)
      |                                ^
oddeven.cpp:105:14: error: 'string' was not declared in this scope
  105 | bool cmpBig2(string s1,string s2)
      |              ^~~~~~
oddeven.cpp:105:24: error: 'string' was not declared in this scope
  105 | bool cmpBig2(string s1,string s2)
      |                        ^~~~~~
oddeven.cpp:105:33: error: expression list treated as compound expression in initializer [-fpermissive]
  105 | bool cmpBig2(string s1,string s2)
      |                                 ^