首页 电脑 电脑学堂 查看内容

浅析依赖注入

2014-11-13 10:59 925 0

摘要: 浅析依赖注入      菜鸟D曾经的一个项目使用的是Spring.Net框架,是将java的Spring框架移植到.Net平台上来。但是它的核心思想没有发生什么变化,依然...
关键词: 用者 控件 nbsp 耦合 public BindFrame void 一个 Spring 但是

题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6=48),求所有结果中,含有‘3’且该数字出现频率最大,若频率相等,输出数字最大的。暴力解决之AC代码:[cpp] view plaincopy#include <stdio.h>  #include <map>  #include <string.h>  #include <algorithm>  #define LL __int64  using namespace std;  LL a[20],cnt,k;  map<LL,LL> ans;  map<LL,LL>::iterator it;  bool cmp(LL a,LL b)  {      return a>b;  }    LL cal(LL sum,LL temp,LL op)  {      if(op==0)          return sum+temp;      if(op==1)          return sum-temp>0? sum-temp:temp-sum;      if(op==2)          return sum*temp;      if(op==3)          return sum/temp;  }    void dfs(LL x,LL sum)  {      if(x==cnt)      {          LL tempsum=sum;          while(tempsum)          {              if(tempsum%10==3)              {                  ans[sum]++;                  k++;                  //printf("%I64d\n",sum);                  break;              }              tempsum/=10;          }          return  ;      }      for(LL i=0;i<4;i++)      {          if(i==3 && a[x]==0)              continue;          LL temp=cal(sum,a[x],i);          dfs(x+1,temp);      }  }    int main()  {      char s[100];      LL len,i;      while(gets(s))      {          if(s[0]=='#')              break;          ans.clear();          len=strlen(s);          LL temp;          cnt=temp=0;          for(i=0;i<len;i++)          {              if(s[i]==' ')              {                  a[cnt++]=temp;                  temp=0;                  continue;              }              temp=temp*10+s[i]-'0';          }          a[cnt++]=temp;          k=0;          dfs(1,a[0]);          if(k)          {              LL maxt=-1,maxans;              for(it=ans.begin();it!=ans.end();it++)              {                  if(maxt<=(it->second))                  {                      maxt=it->second;                      maxans=it->first;                      if((it->first)>maxans)                          maxans=it->first;                  }              }              printf("%I64d\n",maxans);          }          else              printf("No result\n");      }      return 0;  }  
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部