HDU 2410 Barbara Bennett's Wild Numbers (想法題)

來源:互聯網
上載者:User

標籤:scan   i++   problem   tar   條件   show   code   代碼   include   

題目連結:HDU 2410 Barbara Bennett‘s Wild Numbers

題意:給出兩串數w,s(長度同樣),第一串中有“?”,問“?”取的值使w相應的數大於s相應的數 的最慷慨案數。

思路:W,S一一相應比較;

遇到第一個’?‘之前比較情況

1.w[i]<s[i] 方案數0種;break;

2.w[i]>s[i] break。

之後有n個‘’?‘ 方案數就有10的n次方種。

3.w[i]=s[i] 繼續比較。反覆1.2兩個條件。

遇到’?‘

1.能取數個數是 ’9‘-x[i]。

之後10的n次方。

2.取等於x[i] ,繼續比較。


AC代碼:


#include<stdio.h>#include<string.h>char w[20],x[20];int get(int i,int temp,int len){    int j;    for(j=i+1; j<len; j++)    {        if(w[j]==‘?

‘) temp*=10; } return temp;}int main(){ int len,i,j; while(scanf("%s",w)!=EOF) { if(strcmp(w,"#")==0) break; scanf("%s",x); len=strlen(w); int ans=0; for(i=0; i<len; i++) { if(w[i]==‘?‘) ans+=get(i,‘9‘-x[i],len); else { if(w[i]==x[i]) continue; if(w[i]>x[i]) ans+=get(i,1,len); break; } } printf("%d\n",ans); } return 0;}/*12?

4?1235412?5?

12354*/



HDU 2410 Barbara Bennett&#39;s Wild Numbers (想法題)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.