1084  利用字符串string的可加性

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main ()
 4 {
 5     int x,n;
 6     cin>>x>>n;
 7     string str="x";
 8     str[0]='0'+x;
 9     for (int i=2;i<=n;i++) {
10         string  tmp="";
11         string  t2="x";
12         char k=str[0]; int num=1;
13         for (int j=1;j<str.size();j++) {
14             if (str[j]==k) num++;
15             else {
16                 t2[0]=k;       tmp+=t2; 
17                 t2[0]='0'+num; tmp+=t2;
18                 k=str[j]; num=1;
19             }
20         }
21         t2[0]=k;       tmp+=t2; 
22         t2[0]='0'+num; tmp+=t2;
23         str=tmp;
24     }
25     cout<<str<<endl;
26     return 0;
27 }

1085 利用map 实现学校名称的映射

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+3;
 4 struct T {
 5     string name;
 6     double sum;
 7     int p;
 8     int num;
 9 };
10 map < string,int > mp;
11 T t[N];
12 int cnt;
13 int n;
14 bool cmp (T x,T y) {
15     if (x.p==y.p) {
16         if (x.num==y.num)
17             return x.name<y.name;
18         return x.num<y.num;
19     }
20     return x.p>y.p;
21 }
22 int main ()
23 {
24     ios::sync_with_stdio(false);// 不加这句话会超时
25     cin>>n;
26     for (int i=1;i<=n;i++) {
27         string s1,s2; int val; double w;
28         //getchar();// 很奇怪 ios::同步后就不需要加 而不同步就需要加
29         cin>>s1>>val>>s2;
30         for (int j=0;j<s2.size();j++) 
31             if (s2[j]>='A'&&s2[j]<='Z') 
32                 s2[j]=s2[j]-'A'+'a';
33         if (s1[0]=='B')  w=(double)val/1.5;
34         else if (s1[0]=='A')  w=(double)val;
35         else                  w=(double)val*1.5;
36         if (!mp[s2]) {
37             mp[s2]=++cnt;
38             t[cnt].name=s2;
39             t[cnt].num=1;
40             t[cnt].sum=w;
41         }
42         else {
43             int id=mp[s2];
44             t[id].num++;
45             t[id].sum+=w;
46         }
47     }
48     for (int i=1;i<=cnt;i++)
49         t[i].p=(int)t[i].sum;
50     sort (t+1,t+1+cnt,cmp);
51     cout<<cnt<<"\n";
52 
53     int k=1; int i=1;  int point=t[1].p;
54     cout<<k<<" "<<t[i].name<<" "<<t[i].p<<" "<<t[i].num<<endl;
55     for (i=2;i<=cnt;i++) {
56         if (t[i].p==point)
57             cout<<k<<" "<<t[i].name<<" "<<t[i].p<<" "<<t[i].num<<endl;
58         else {
59             point=t[i].p;
60             k=i;
61             cout<<k<<" "<<t[i].name<<" "<<t[i].p<<" "<<t[i].num<<endl;
62         }
63 
64     }
65     return 0;
66 }