HDU Quicksum

来源:互联网 发布:上海嘉桥数据咨询公司 编辑:程序博客网 时间:2024/05/16 18:33
题意:
ACM: 1*1 + 2*3 + 3*13 = 46MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650
ACMMID CENTRALREGIONAL PROGRAMMING CONTESTACNA C MABCBBC#
 
Sample Output
46650469049751415
自己写的代码虽然通过 , 但是却发现有更简洁的 代码:
#if 0#include<bits/stdc++.h>using namespace std;int main(){  map<char,int> m ;  for(int i=65; i<=90; i++)  {   m[char(i)] = i-64;  }m[' '] = 0 ;string s;while(getline(cin,s) && s!="#"){int sum=0;for(int i=0; i<s.size(); i++){sum +=(i+1)*m[s[i]] ;}cout << sum << endl;}return 0;}#endif 

//更简洁的代码 :
          #if 0                   //更简洁,更快 ,更完美的代码,初衷~ #include<bits/stdc++.h>using namespace std;int main(){     char  s ;    ios::sync_with_stdio(false) ;    int sum=0 , i=1;    while(1)    {    s=getchar() ;        if(s=='#') break;        else if(s=='\n')      {      cout << sum <<endl;            sum=0;    i=1;  //continue; 在这里没有用     }  else   {  sum +=(s==' ')?0:i*(s-'A'+1);  i++;     }   }}#endif