summaryrefslogtreecommitdiff
path: root/1.2
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-04-16 19:06:32 +0800
committerIru Cai <mytbk920423@gmail.com>2018-04-16 19:06:32 +0800
commitad4e2420e822b8a115aac6124307b89447578782 (patch)
tree6f4db875081597e2e64dd4221a97bbff25503dcc /1.2
parenta7721767628a51b752ad3a96eb334734241dcd8b (diff)
downloadusaco-ad4e2420e822b8a115aac6124307b89447578782.tar.xz
1.2~1.5
Diffstat (limited to '1.2')
-rw-r--r--1.2/beads.c64
-rw-r--r--1.2/friday.c48
-rw-r--r--1.2/ride.c32
3 files changed, 144 insertions, 0 deletions
diff --git a/1.2/beads.c b/1.2/beads.c
new file mode 100644
index 0000000..9f21528
--- /dev/null
+++ b/1.2/beads.c
@@ -0,0 +1,64 @@
+/*
+ID: mytbk921
+LANG: C
+TASK: beads
+*/
+
+#include <stdio.h>
+#define MAXL 360
+
+int next(int t,int n)
+{
+ return (t==n-1)?0:(t+1);
+}
+
+int last(int t,int n)
+{
+ return (t==0)?(n-1):(t-1);
+}
+
+int main()
+{
+ FILE *fin=fopen("beads.in","r");
+ FILE *fout=fopen("beads.out","w");
+
+ int n;
+ int i,l,r;
+ int count,countr,max=0;
+ char beads[MAXL],color;
+ fscanf(fin,"%d%s",&n,beads);
+
+ for (i=0;i<n;i++){ //break between i-1 and i
+ count=0;countr=0;
+ for (l=last(i,n);l!=i;l=last(l,n)){ //search left
+ if (count==0){ //the first bead
+ color=beads[l];
+ ++count;
+ }
+ else if (beads[l]=='w'||color=='w'||beads[l]==color){ //have a white or is the same color
+ ++count;
+ if (color=='w') color=beads[l];
+ continue;
+ }
+ else break;
+ }
+ l=next(l,n); //the final leftmost
+ for (r=i;r!=l;r=next(r,n)){ //search right
+ if (countr==0){
+ color=beads[r];
+ ++countr;
+ }
+ else if (beads[r]=='w'||color=='w'||beads[r]==color){
+ ++countr;
+ if (color=='w') color=beads[r];
+ continue;
+ }
+ else break;
+ }
+ if (countr+count>max)
+ max=countr+count;
+ }
+ fprintf(fout,"%d\n",max);
+ return 0;
+}
+
diff --git a/1.2/friday.c b/1.2/friday.c
new file mode 100644
index 0000000..c0b2ceb
--- /dev/null
+++ b/1.2/friday.c
@@ -0,0 +1,48 @@
+/*
+ID: mytbk921
+LANG: C
+TASK: friday
+*/
+
+#include <stdio.h>
+
+int isleap(int year)
+{
+ if (year%4==0 && (year%100!=0 || year%400==0))
+ return 1;
+ else
+ return 0;
+}
+
+const int DaysOfMonth[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
+
+int main()
+{
+ int n; //years eclipsed
+ int year;
+ int nDays[7]={0}; //number of Sat. to Fri.
+ int wDay=2+12; //the week day,1900.01.01 is Monday(2)
+ int i;
+ FILE *fin=fopen("friday.in","r");
+ FILE *fout=fopen("friday.out","w");
+
+ fscanf(fin,"%d",&n);
+ for (year=1900;year<1900+n;year++){
+ int type=isleap(year);
+ for (i=0;i<12;i++){
+ wDay%=7;
+ nDays[wDay]++;
+ wDay+=DaysOfMonth[type][i];
+ }
+ }
+ for (i=0;i<7;i++){
+ if (i)
+ fputc(' ',fout);
+ fprintf(fout,"%d",nDays[i]);
+ }
+ fputc('\n',fout);
+ fclose(fin);
+ fclose(fout);
+ return 0;
+}
+
diff --git a/1.2/ride.c b/1.2/ride.c
new file mode 100644
index 0000000..2a68239
--- /dev/null
+++ b/1.2/ride.c
@@ -0,0 +1,32 @@
+/*
+ID: mytbk921
+LANG: C
+TASK: ride
+*/
+
+#include <stdio.h>
+#define MODN 47
+
+int main()
+{
+ FILE *fin=fopen("ride.in","r");
+ FILE *fout=fopen("ride.out","w");
+ int p[2]={1,1}; //2 products
+ char str[2][8];
+
+ int i,j;
+ fscanf(fin,"%s%s",str[0],str[1]);
+ for (i=0;i<2;i++){
+ for (j=0;str[i][j];j++){
+ p[i]*=str[i][j]-'A'+1;
+ p[i]%=MODN;
+ }
+ }
+ if (p[0]==p[1])
+ fprintf(fout,"GO\n");
+ else
+ fprintf(fout,"STAY\n");
+
+ return 0;
+}
+