【模拟】bzoj2760 [JLOI2011]小A的烦恼

注意细节和初始化。

 1 #include<cstdio>
 2 #include<string>
 3 #include<algorithm>
 4 #include<iostream>
 5 using namespace std;
 6 string ans[110],tmp[110][110];
 7 int m,cnt[110],maxv,maxm,n;
 8 int Calc(const string &s,const char &c)
 9 {
10     if(s.empty()) return 0;
11     int p=0,res=0,len=s.length(); string t=s;
12     while(1)
13       {
14         t=t.substr(p,len-p); p=t.find(c);
15         if(p==-1) break;
16         res++; p++;
17       }
18     return res+1;
19 }
20 int main()
21 {
22     scanf("%d",&n);
23     for(int i=1;i<=n;i++)
24       {
25         scanf("%d",&m); maxm=max(maxm,m);
26         for(int j=0;j<=m;j++) cin>>tmp[i][j];
27       }
28     for(int i=1;i<=n;i++)
29       {
30         maxv=0;
31         for(int j=0;j<=maxm;j++)
32           {
33             ans[j]+=tmp[i][j];
34             maxv=max(maxv,cnt[j]=(j==0 ? 1 : Calc(tmp[i][j],',')));
35           }
36         for(int j=0;j<=maxm;j++)
37           for(int k=0;k<=maxv-cnt[j]-(i==n)-(!cnt[j]);k++)
38             ans[j]+=",";
39       }
40     for(int i=0;i<=maxm;i++) cout<<ans[i]<<endl;
41     return 0;
42 }

 

posted @ 2014-11-03 10:09  AutSky_JadeK  阅读(239)  评论(0编辑  收藏  举报
TVアニメ「Charlotte(シャーロット)」公式サイト TVアニメ「Charlotte(シャーロット)」公式サイト