Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

进10000名了,纪念下,附思路清晰的简短代码,大牛请忽略就好

Posted by docdoc at 2014-08-31 20:01:31 on Problem 2190
#include <iostream>

using namespace std;

int main()
{
    char is[15];
    scanf("%s",is);
    int sum=0,index=0;
    for(int i=9;i>=0;i--){
        if(is[i]=='X'){//不能写is[9]
            sum+=10;
            continue;
        }if(is[i]=='?'){
           index=i;
           continue;
        }
        sum+=((is[i]-48)*(10-i));
    }
    int n=(index==9)?10:9;
    int tmp=0,ans=-1;
    for(int i=0;i<=n;i++){
        tmp=sum+i*(10-index);
        if(tmp%11==0){
            ans=i;
            break;
        }
    }
    if(ans==10)puts("X");
    else printf("%d\n",ans);
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator