标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<iostream> 5 #include<algorithm> 6 #include<map> 7 8 using namespace std; 9 10 int N; 11 12 map <char,double> ar; 13 14 int main(){ 15 ar[‘C‘] = 12.01; 16 ar[‘H‘] = 1.008; 17 ar[‘O‘] = 16.00; 18 ar[‘N‘] = 14.01; 19 20 scanf("%d",&N); 21 22 while(N --){ 23 char ch[100]; 24 25 scanf("%s",ch); 26 int a = strlen(ch); 27 double Ans = 0; 28 29 for(int i = 0;i < a;++ i){ 30 if(ch[i] >= ‘A‘ && ch[i] <= ‘Z‘){ 31 int Pos = i + 1; 32 double sum = 0; 33 bool flag = false; 34 35 while(ch[Pos] >= ‘0‘ && ch[Pos] <= ‘9‘&& Pos < a){ 36 sum = sum * 10 + int(ch[Pos] - ‘0‘); 37 Pos ++; 38 flag = true; 39 } 40 41 if(!flag){ 42 sum = 1; 43 } 44 Ans += sum * ar[ch[i]]; 45 } 46 } 47 printf("%.3f\n",Ans); 48 } 49 50 return 0; 51 }
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<iostream> 5 #include<algorithm> 6 7 using namespace std; 8 9 int N; 10 11 struct yes{ 12 char ch[250]; 13 }p[150]; 14 15 int main(){ 16 scanf("%d",&N); 17 18 for(int i = 1;i <= N;++ i){ 19 scanf("%s",p[i].ch); 20 21 int a = strlen(p[i].ch); 22 23 for(int j = 0;j < a;++ j){ 24 p[i].ch[j + a] = p[i].ch[j]; 25 } 26 27 string min = "ZZZZZZZZZZZZZZZZ"; 28 29 for(int j = 0;j < a;++ j){ 30 int k = j + a - 1; 31 string s; 32 33 for(int g = j;g <= k;++ g) 34 s += p[i].ch[g]; 35 // cout << s << endl; 36 if(s < min){ 37 min = s; 38 // cout << "min:: " << min << endl; 39 } 40 } 41 42 for(int j = 0;j < min.length();++ j){ 43 cout << min[j]; 44 } 45 46 printf("\n"); 47 } 48 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/sxprovence/p/4666201.html