bnuoj 20832 Calculating Yuan Fen(暴力模拟)

http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832

【题意】:
 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符分别加上(ST-'A'),然后得到的数组分别连起来组成字符串,相邻两个字符相加,取各位数,赋值到下一行,每行讲减少一个字符,直到出现3个字符为100时,输出这时候的ST

【题解】:
 完全暴力模拟
【code】:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string>
 4 #include <string.h>
 5 #include <math.h>
 6 #include <algorithm>
 7 
 8 using namespace std;
 9 
10 int getST(char *names)
11 {
12     int a[100];
13     int len = strlen(names);
14     int i;
15     int ST;
16     int b[1000],cnt=0;
17     for(ST=1;ST<=10000;ST++)
18     {
19         for(i=0;i<len;i++)
20         {
21             a[i]=names[i]-'A'+ST;
22         }
23         cnt=0;
24         for(i=len-1;i>=0;i--)
25         {
26             int m = a[i];
27             while(m)
28             {
29                 b[cnt]=m%10;
30                 m=m/10;
31                 cnt++;
32             }
33         }
34         for(i=0;i<cnt/2;i++)
35         {
36             swap(b[i],b[cnt-i-1]);
37         }
38         int j;
39         for(i=0;i<cnt-3;i++)
40         {
41             for(j=0;j<cnt-1-i;j++)
42             {
43                  b[j]=(b[j]+b[j+1])%10;
44             }
45         }
46 
47         if(b[0]==1&&b[1]==0&&b[2]==0)   return ST;
48     }
49     return -1;
50 }
51 
52 int main()
53 {
54     char names[100];
55     while(~scanf("%s",names))
56     {
57         int ans = getST(names);
58         if(ans==-1)
59         {
60             puts(":(");
61         }
62         else
63         {
64             printf("%d
",ans);
65         }
66     }
67     return 0;
68 }
原文地址:https://www.cnblogs.com/crazyapple/p/3335285.html