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

傻了,如此简单

Posted by zxj1015 at 2015-04-29 11:11:25 on Problem 1152
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <stack>
#include <string.h>
#include <vector>
using namespace std;

char buf[300000];

int ToInt(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  } else if (c >= 'A' && c <= 'Z') {
    return c - 'A' + 10;
  } else {
    return c - 'a' + 36;
  }
}
int main() {
  while (scanf("%s", buf) != EOF) {
    int min_base = 2;
    long len = strlen(buf);
    for (long i = 0; i < len; ++i) {
      if (ToInt(buf[i]) + 1 > min_base) {
        min_base = ToInt(buf[i]) + 1;
      }
    }
    bool flag = false;
    for (int base = min_base; base <= 62; ++base) {
      int cur = 0;
      for (int i = -1; i < len - 1; ++i) {
        cur = (cur % (base - 1)) * base + ToInt(buf[i + 1]);
      }
      if (cur % (base - 1) == 0) {
        printf("%d\n", base);
        flag = true;
        break;
      }
    }
    if (flag == false) {
      printf("such number is impossible!\n");
    }
  }
}







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