• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 40, 文章 - 0, 評論 - 19, 引用 - 0
            數據加載中……

            PKU 3337 Expression Evaluator

            這個題目A的很傻,一次接入三個字符,然后自己不停的來處理各種情況的效果,呵呵,各種格式是應該注意的,空格算是小陷阱?呵呵,所以一般復制那個sample再改就好了,freopen("a.in","r",stdin);freopen("a.out","w",stdout);這種文件讀入讀出的方式對觀察自己的輸出結果很有好處,推薦使用防止PE,呵呵,也許是北大的數據比較弱,這個同樣的題目在天大的OJ就過不了~WA的很郁悶。。。
              1Source Code
              2
              3Problem: 3337  User: hongtaozhy 
              4Memory: 296K  Time: 0MS 
              5Language: G++  Result: Accepted 
              6
              7Source Code 
              8#include<stdio.h>
              9#include<string.h>
             10char res[10000];
             11char fes[10000];
             12char zd[26]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};
             13bool mark[26];
             14int main(){
             15    int n;
             16    int sum;
             17    int key ;
             18    //freopen("g.in","r",stdin);
             19    //freopen("gg.in","w",stdout);  
             20    scanf("%d\n",&n);
             21    int len ;    
             22    while(n--){
             23        key = 0 ;
             24    memset(mark,0,sizeof(mark));       
             25     for(int i = 0 ;i < 26 ; i++ )
             26     zd[i]=i+1;
             27               
             28    sum = 0 ;
             29    gets(fes);
             30    printf("Expression: %s\n",fes);
             31    
             32    
             33    len =  strlen ( fes );
             34    int t = 0 ;
             35    for(int i = 0 ;i < len ; i++ ){
             36    if(fes[i]!=' ') res[t++]=fes[i];
             37    if(fes[i]=='\0')               { res[t++]=0;res[t++]=0;}
             38    }

             39  //   printf("%s\n",res);
             40    len = strlen ( res );
             41    forint i = 0 ; i < len ; i++ ){
             42         if(res[i]<='z'&&res[i]>='a'&&res[i+1]==res[i+2]){
             43             if(key == 0)
             44             sum += zd[res[i]-'a'];
             45             else 
             46             sum -= zd[res[i]-'a'];
             47             if(res[i+1]=='-')
             48             zd[res[i]-'a']--;
             49             else if(res[i+1]=='+')
             50             zd[res[i]-'a']++;
             51             mark[res[i]-'a']=1;
             52           
             53             i+=2;
             54             continue;
             55         }

             56         else if(res[i+2]<='z'&&res[i+2]>='a'&&res[i+1]==res[i]){           
             57             if(res[i+1]=='-')
             58             zd[res[i+2]-'a']--;
             59             else if(res[i+1]=='+')
             60             zd[res[i+2]-'a']++;
             61             if(key == 0)
             62             sum += zd[res[i+2]-'a'];
             63             else 
             64             sum -= zd[res[i+2]-'a'];
             65             mark[res[i+2]-'a']=1;
             66          
             67              i+=2;
             68             continue;
             69         }

             70         else  if(res[i]<='z'&&res[i]>='a'){
             71       
             72             if(key == 0)
             73             sum += zd[res[i]-'a'];
             74             else 
             75             sum -= zd[res[i]-'a']; 
             76             mark[res[i]-'a']=1;
             77             if(res[i+1]=='+')                 key=0;
             78             else key=1;
             79         }

             80         else if(res[i]=='-'&&res[i+1]=='-'&&res[i+2]=='+')
             81         key=0;
             82         else if(res[i]=='+'&&res[i+1]=='+'&&res[i+2]=='-')
             83         key=1;
             84         else if(res[i]=='-'&&res[i+1]=='+'&&res[i+2]=='+')
             85         key=1;
             86         else if(res[i]=='+'&&res[i+1]=='-'&&res[i+2]=='-')
             87         key=0;
             88         else if(res[i]=='+'&&res[i+1]<='z'&&res[i+1]>='a')
             89         key=0;
             90         else if(res[i]=='-'&&res[i+1]<='z'&&res[i+1]>='a')
             91         key=1;
             92         else if(res[i]=='+'&&res[i+1]=='+'&&res[i+2]=='+')
             93         key=0;
             94         else if(res[i]=='-'&&res[i+1]=='-'&&res[i+2]=='-')
             95         key=1;
             96    }

             97        
             98        
             99   printf("value = %d\n",sum);
            100   for(int i = 0 ; i < 26 ; i ++ ){
            101    if(mark[i]!=0)
            102    printf("%c = %d\n",i+'a',zd[i]);
            103    }

            104    }

            105 //   while(1);
            106return 0 ; 
            107}

            108
            109

            posted on 2008-07-18 22:45 hadn't 閱讀(232) 評論(0)  編輯 收藏 引用

            99久久中文字幕| 国产免费久久精品丫丫| 97香蕉久久夜色精品国产 | 精品久久久久久久久免费影院| 久久久久亚洲精品无码网址| 久久久久久久久波多野高潮| 国产午夜福利精品久久2021| 国产免费久久精品丫丫| 日日躁夜夜躁狠狠久久AV| 久久午夜电影网| 99久久精品免费看国产一区二区三区| 97久久超碰国产精品旧版| 久久影院午夜理论片无码 | 国产精品久久久久9999高清| 久久91这里精品国产2020| 伊人久久大香线蕉av一区| 久久被窝电影亚洲爽爽爽| 久久久久久午夜精品| 激情久久久久久久久久| 久久精品国产亚洲AV无码麻豆 | 99久久精品国产麻豆| 亚洲国产香蕉人人爽成AV片久久 | 97r久久精品国产99国产精| 欧美麻豆久久久久久中文| 九九99精品久久久久久| 久久综合综合久久综合| 欧美久久天天综合香蕉伊| 久久精品国产一区二区电影| 久久青草国产精品一区| 午夜天堂av天堂久久久| 一本色综合网久久| 久久只有这里有精品4| 一本大道久久东京热无码AV| 热久久国产欧美一区二区精品| 青青草原综合久久| 久久九九亚洲精品| 久久91精品国产91久久麻豆| 精品久久久久久亚洲| 久久久综合九色合综国产| 久久综合综合久久狠狠狠97色88| 久久精品国产精品青草app|