同第三个点,求解答

P1603 斯诺登的密码

KKarshilov @ 2017-07-05 12:40:37

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
using namespace std;
string s[7],s1[7],s2; 
bool a[7];
int comp(string x,string y)
{
    if(x+y>y+x)
      return 0;
    if(x+y<y+x)
      return 1;
    return 0;
}
int main(int argc, char** argv) 
{
    for(int i=1;i<=6;i++)
      cin>>s[i];
    for(int i=1;i<=6;i++)
    {
        if(s[i]=="zero")
          {s1[i]="00";a[i]=1;}
        else if(s[i]=="one"||s[i]=="a"||s[i]=="first")
          {s1[i]="01";a[i]=1;}
        else if(s[i]=="two"||s[i]=="second"||s[i]=="both")
          {s1[i]="04";a[i]=1;}
        else if(s[i]=="three"||s[i]=="third"||s[i]=="another")
          {s1[i]="09";a[i]=1;}
        else if(s[i]=="four")
          {s1[i]="16";a[i]=1;}
        else if(s[i]=="five")
          {s1[i]="25";a[i]=1;}
        else if(s[i]=="six")
          {s1[i]="36";a[i]=1;}
        else if(s[i]=="seven")
          {s1[i]="49";a[i]=1;}
        else if(s[i]=="eight")
          {s1[i]="64";a[i]=1;}
        else if(s[i]=="nine")
          {s1[i]="81";a[i]=1;}
        else if(s[i]=="ten")
          {s1[i]="00";a[i]=1;}
        else if(s[i]=="eleven")
          {s1[i]="21";a[i]=1;}
        else if(s[i]=="twelve")
          {s1[i]="44";a[i]=1;}
        else if(s[i]=="thirteen")
          {s1[i]="69";a[i]=1;}
        else if(s[i]=="fourteen")
          {s1[i]="96";a[i]=1;}
        else if(s[i]=="fifteen")
          {s1[i]="25";a[i]=1;}
        else if(s[i]=="sixteen")
          {s1[i]="56";a[i]=1;}
        else if(s[i]=="seventeen")
          {s1[i]="89";a[i]=1;}
        else if(s[i]=="eighteen")
          {s1[i]="24";a[i]=1;}
        else if(s[i]=="nineteen")
          {s1[i]="61";a[i]=1;}
        else if(s[i]=="twenty")
          {s1[i]="00";a[i]=1;}
    }
    sort(s1+1,s1+7,comp);
    for(int i=1;i<=6;i++)
    {
      s2+=s1[i]; 
    }
    for(int i=0;i<s2.size();i++)
      if(s2[i]!='0'||(s2[i-1]!='0'&&i>=1))
        cout<<s2[i];
    cout<<endl;
    return 0;
}

by KKarshilov @ 2017-07-05 12:47:02

已解决,第三个点没有数字,输出0

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
using namespace std;
string s[7],s1[7],s2; 
bool a[7];
int b=0;
int comp(string x,string y)
{
    if(x+y>y+x)
      return 0;
    if(x+y<y+x)
      return 1;
    return 0;
}
int main(int argc, char** argv) 
{
    for(int i=1;i<=6;i++)
      cin>>s[i];
    for(int i=1;i<=6;i++)
    {
        if(s[i]=="zero")
          {s1[i]="00";a[i]=1;}
        else if(s[i]=="one"||s[i]=="a"||s[i]=="first")
          {s1[i]="01";a[i]=1;}
        else if(s[i]=="two"||s[i]=="second"||s[i]=="both")
          {s1[i]="04";a[i]=1;}
        else if(s[i]=="three"||s[i]=="third"||s[i]=="another")
          {s1[i]="09";a[i]=1;}
        else if(s[i]=="four")
          {s1[i]="16";a[i]=1;}
        else if(s[i]=="five")
          {s1[i]="25";a[i]=1;}
        else if(s[i]=="six")
          {s1[i]="36";a[i]=1;}
        else if(s[i]=="seven")
          {s1[i]="49";a[i]=1;}
        else if(s[i]=="eight")
          {s1[i]="64";a[i]=1;}
        else if(s[i]=="nine")
          {s1[i]="81";a[i]=1;}
        else if(s[i]=="ten")
          {s1[i]="00";a[i]=1;}
        else if(s[i]=="eleven")
          {s1[i]="21";a[i]=1;}
        else if(s[i]=="twelve")
          {s1[i]="44";a[i]=1;}
        else if(s[i]=="thirteen")
          {s1[i]="69";a[i]=1;}
        else if(s[i]=="fourteen")
          {s1[i]="96";a[i]=1;}
        else if(s[i]=="fifteen")
          {s1[i]="25";a[i]=1;}
        else if(s[i]=="sixteen")
          {s1[i]="56";a[i]=1;}
        else if(s[i]=="seventeen")
          {s1[i]="89";a[i]=1;}
        else if(s[i]=="eighteen")
          {s1[i]="24";a[i]=1;}
        else if(s[i]=="nineteen")
          {s1[i]="61";a[i]=1;}
        else if(s[i]=="twenty")
          {s1[i]="00";a[i]=1;}
    }
    sort(s1+1,s1+7,comp);
    for(int i=1;i<=6;i++)
    {
      s2+=s1[i]; 
    }
    for(int i=0;i<s2.size();i++)
      if(s2[i]!='0'||(s2[i-1]!='0'&&i>=1))
        cout<<s2[i];
    for(int i=1;i<=6;i++)
    {
        if(!a[i])
          b++;
        if(b==6)
        {
          cout<<"0"<<endl;
          return 0;
        }
    }
    cout<<endl;
    return 0;
}

|