USACO Section 1.1

这是4道大水题。

因为我看有些题解写的很丑陋,就把我的代码发上来。

第一题是我早期作品,丑陋不堪......

 1 #include <cstdio>
 2 #include <iostream>
 3 using namespace std;
 4 
 5 char a[10];
 6 char b[10];
 7 
 8 int pan(char c)
 9 {
10     if(c=='B') return 2;
11     if(c=='C') return 3;
12     if(c=='D') return 4;
13     if(c=='E') return 5;
14     if(c=='F') return 6;
15     if(c=='G') return 7;
16     if(c=='H') return 8;
17     if(c=='I') return 9;
18     if(c=='J') return 10;
19     if(c=='K') return 11;
20     if(c=='L') return 12;
21     if(c=='M') return 13;
22     if(c=='N') return 14;
23     if(c=='O') return 15;
24     if(c=='P') return 16;
25     if(c=='Q') return 17;
26     if(c=='R') return 18;
27     if(c=='S') return 19;
28     if(c=='T') return 20;
29     if(c=='U') return 21;
30     if(c=='V') return 22;
31     if(c=='W') return 23;
32     if(c=='X') return 24;
33     if(c=='Y') return 25;
34     if(c=='Z') return 26;
35     return 1;
36 }
37 
38 int xiuxi1()
39 {
40     int s=1;
41     for(int i=0;i<=9;i++)
42     {
43         s*=pan(a[i]);
44         s%=47;
45     }
46     return s;
47 }
48 
49 int xiuxi2()
50 {
51     int s=1;
52     for(int i=0;i<=9;i++)
53     {
54         s*=pan(b[i]);
55         s%=47;
56     }
57     return s;
58 
59 }
60 
61 int main()
62 {
63     cin>>a;
64     cin>>b;
65     //printf("xiuxi1:%d xiuxi2:%d
",xiuxi1(),xiuxi2());
66     if(xiuxi1()==xiuxi2())
67     {
68         printf("GO");
69         return 0;
70     }
71     printf("STAY");
72     return 0;
73 }
P1200 代码在此

好,下三题是我最近作品,欣赏较为成型的代码风格吧。

 1 #include <cstdio>
 2 #include <iostream>
 3 using namespace std;
 4 string name[20];
 5 int n;
 6 int findNum(string a)
 7 {
 8     for(int i=1;i<=n;i++) if(name[i]==a) return i;
 9     printf("-1
");
10     return -1;
11 }
12 int get[20];
13 int main()
14 {
15     scanf ("%d",&n);
16     for(int i=1;i<=n;i++) cin>>name[i];
17     for(int i=1;i<=n;i++)
18     {
19         string c;
20         cin>>c;
21         int now=findNum(c),man,money;
22         scanf("%d%d",&money,&man);
23         get[now]-=money;
24         if(man)get[now]+=money-(money/man)*man;
25         //if(man){cout<<name[now];printf(" +%d
",money-(money/man)*man);}
26         if(man)money/=man;
27         for(int j=1;j<=man;j++)
28         {
29             cin>>c;
30             get[findNum(c)]+=money;
31             //cout<<c<<'+'<<money<<endl;
32         }
33     }
34     for(int i=1;i<=n;i++) cout<<name[i]<<" "<<get[i]<<endl;
35     return 0;
36 }
P1201
 1 #include <cstdio>
 2 using namespace std;
 3 
 4 int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
 5 int week[8],now=1;
 6 bool is_run_year(int a)
 7 {
 8     if(a%400==0) return 1;
 9     if(a%100==0) return 0;
10     if(a%4==0)   return 1;
11                  return 0;
12 }
13 int main()
14 {
15     int n;
16     scanf ("%d",&n);
17     int y=1900,m=1,d=1;
18     for(;y<1900+n;d++,now++)
19     {
20         if(is_run_year(y)) month[2]=29;
21         else month[2]=28;
22         if(d>month[m]) d=1,m++;
23         if(m>12) m=1,y++;
24         if(now>7) now=1;
25         if(d==13)
26         {
27             //printf("%d.%d.%d is %d
",y,m,d,now);
28             week[now]++;
29         }
30     }
31     printf("%d %d %d %d %d %d %d",week[6],week[7],week[1],week[2],week[3],week[4],week[5]);
32     return 0;
33 }
P1202
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 using namespace std;
 5 int n;
 6 char c[999];
 7 int find_sum(int p,int k)
 8 {
 9     int ans=0;
10     char flag=c[p];int pp=p;
11     while(flag=='w' && pp>0 && pp<2*n+1)
12     {
13         pp+=k;
14         flag=c[pp];
15     }
16     while(p>0 && p<2*n+1)
17     {
18         if(c[p]==flag || c[p]=='w') ans++;
19         else break;
20         p+=k;
21     }
22     return ans;
23 }
24 int main()
25 {
26     scanf ("%d",&n);
27 
28     cin>>c+1;
29     for(int i=1;i<=n;i++)
30     {
31         c[i+n]=c[i];
32     }
33     int ans=0;
34     for(int i=1;i<=n*2;i++)
35     {
36         int now=find_sum(i,-1)+find_sum(i+1,1);
37         //printf("%d now = %d
",i,now);
38         ans=max(ans,now);
39     }
40     //printf("%d
",ans);
41     printf("%d",min(ans,n));
42     return 0;
43 }
P1203
以后写工程肯定不止这样......
原文地址:https://www.cnblogs.com/huyufeifei/p/8595965.html