zoukankan      html  css  js  c++  java
  • SHU 414

    题目链接:http://acmoj.shu.edu.cn/problem/414/

    很咸鱼的网上拉了个进制转换模板过来,因为数组开的太小一直WA,后来一气之下MAXN开到1e5,真是蓝瘦……

    后来实在觉得那样傻乎乎套模板真的很咸鱼,实在没有脸面贴出来

    就自己重新理解了一遍模板,适当修改了之后再发出来(具体这个模板为什么是这样请看:http://www.cnblogs.com/dilthey/p/7141714.html):

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<stack>
     4 #define MAXN 20
     5 using namespace std; 
     6 stack<int> ans;
     7 int t[MAXN];
     8 char OldData[MAXN];
     9 int m;
    10 void trans()
    11 {
    12     int i,len,k=0;
    13     len=strlen(OldData);
    14     for(i=len-1;i>=0;i--) t[len-1-i] = OldData[i] - (OldData[i]<='9' ? 48 : (OldData[i]<'a' ? 55 : 61));
    15     while(len)
    16     {
    17         for(i=len-1;i>=1;i--)
    18         {
    19             t[i-1]+=t[i]%m*26;
    20             t[i]/=m;
    21         }
    22         ans.push(t[0]%m);
    23         t[0]/=m;
    24         while(len>0 && !t[len-1]) len--;
    25     }
    26     
    27     while(!ans.empty())
    28     {
    29         printf("%c",ans.top() + (ans.top()<10 ? '0' : (ans.top()<36 ? 55 : 61)));
    30         ans.pop();
    31     }
    32     printf("
    ");
    33 }
    34 int main()
    35 {
    36     while(scanf("%s",OldData)!=EOF)
    37     {
    38         scanf("%d",&m);
    39         int len=strlen(OldData);
    40         for(int i=0;i<len;i++)
    41         {
    42             if(OldData[i]>='a' && OldData[i]<='j') OldData[i]=OldData[i]-'a'+'0';
    43             else OldData[i]=OldData[i]-'k'+'A';
    44         }
    45         trans();
    46     }
    47 }

    因为这题数据比较水,所以用stack什么的完全不用担心超时,

  • 相关阅读:
    对协程的一些理解
    JUC中Lock和ReentrantLock介绍及源码解析
    JUC中AQS简介
    Executor框架简介
    CyclicBarrier简介
    CountDownLatch简介
    Semaphore简介
    ThreadPoolExecutor简介
    AtomicInteger简介
    synchronized和volatile简介
  • 原文地址:https://www.cnblogs.com/dilthey/p/7142512.html
Copyright © 2011-2022 走看看