POJ- 3094 Quicksum-給規律求字元值
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 15043 | Accepted: 10505 |
Description
A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.
For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces.
A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example
Quicksum calculations for the packets "ACM
" and "MID CENTRAL
":
ACM: 1*1 + 2*3 + 3*13 = 46 MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650
Input
The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.
Output
For each packet, output its Quicksum on a separate line in the output.
Sample Input
ACM MID CENTRAL REGIONAL PROGRAMMING CONTEST ACN A C M ABC BBC #
Sample Output
46 650 4690 49 75 14 15
Source
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <cmath>
using namespace std;
int main()
{
int i,sum;
char c[256];
while(gets(c),c[0]!='#')
{
sum=0;
for(i=0; c[i]!='\0'; ++i)
if(c[i]!=' ')
sum+=((i+1)*(c[i]-'A'+1));
cout<<sum<<endl;
}
return 0;
}
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <cmath>
using namespace std;
int main()
{
int i=1,sum=0;
char c;
while(1)
{
c=getchar();
if(c=='#')
return 0;
if(c=='\n')
{
cout<<sum<<endl;
i=1,sum=0;
continue;
}
if(c!=' ')
sum+=(i*(c-'A'+1));
++i;
}
return 0;
}
相關文章
- 求給定字串的平均字元長度字串字元
- EMS單號規律與順豐單號規律(C#)C#
- A Multiplication Game (博弈,規律)GAM
- 打表找規律
- 一分鐘大發和值走勢規律分析76930566
- normal redundancy Diskgroup裡required_mirror_free_mb值的變化規律ORMUI
- 一分鐘大發和值走勢規律分析46377054
- 求閉合字元字元
- 給請求追加自定義值 $request->offsetSet ($key,$value)
- HDU 6298 Maximum Multiple(找規律)
- HDU 4951 Multiplication table(找規律)
- leedcode-單詞規律
- 軟體行業的發展要尊重軟體工程的價值規律 (轉)行業軟體工程
- 圖片跨域規律探尋跨域
- LeetCode-單詞規律LeetCode
- 索引的應用規律總結索引
- Java欄位初始化規律Java
- 正規表示式 字元和字元類字元
- 軟體開發的21條規律
- LeetCode-290-單詞規律LeetCode
- votedisk在ASM diskgroup上的存放規律ASM
- 正規表示式元字元與普通字元字元
- 求字串連續字元數量字串字元
- Python裡的引用與拷貝規律Python
- python3 中 and 和 or 運算規律Python
- 事理圖譜:事件演化的規律和模式事件模式
- 顧森——《追逐語言的規律》(視訊)
- 一個80後總結就業規律就業
- Shareaholic:社交分享和閱讀的規律
- log_buffer的記憶體分配規律記憶體
- c++ 字元 數值拼接C++字元
- 數值轉換為字元字元
- 常用字元ASCII值字元ASCII
- 利用正規表示式判斷一個給定的字元是否是迴文字元
- 簡單討論資料型別(byte)強制轉化後的數值變化規律資料型別
- 求插值係數
- 這款解謎遊戲的開發者是"自然規律"遊戲
- 計算出大小有什麼走勢圖規律