0%

例题,但书上没代码,就发上来了。前几天理解错题意了,以为是像凯撒密码一样固定位移映射,后来才发现只是个普通的单表替换。书上让用qsort,这几天学了点c++ ,就直接用sort了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<iostream>
#include<cstring>
#include<algorithm>
#define maxn 110
using namespace std;
int main()
{
int i,j,n,k;
int cnt1[26],cnt2[26];
char a[maxn],b[maxn];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
while(cin>>a>>b)
{
k=1;
memset(cnt1,0,sizeof(cnt1));
memset(cnt2,0,sizeof(cnt2));
n=strlen(a);
for(i=0;i<n;i++)
{
cnt1[a[i]-65]++;
cnt2[b[i]-65]++;
}
sort(cnt1,cnt1+26);
sort(cnt2,cnt2+26);
for(i=25;i>=0;i--)
{
if(!k)
break;
if(cnt1[i]!=cnt2[i])
k=0;
}
if(k)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

前天晚上开始看的,昨天和同学出去玩,一天没写,今天下午开始打的,一次Ac,挺简单的。

买的C++的书到了,这几天可能不做了,看看书以后用C++写。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <string.h>
#define maxn 220
int main()
{
int i,j,m,n,x1,y1,x2,y2,temp,z;
char a[maxn],b[maxn];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
while(scanf("%s%s",a,b)!=EOF)
{
m=strlen(a);
n=strlen(b);
if(m>n)
x1=x2=m;
else
x1=x2=n;
y1=y2=m+n;
for(i=0;i<n;i++)
{
z=1;
for(j=0;j<m;j++)
{
if(!z)
break;
if(i+j<n)
if(a[j]==50&b[i+j]==50)
z=0;
}
if(z)
{
if(m+i>n)
x1=m+i;
if(x1<y1)
y1=x1;
}
}
for(i=0;i<m;i++)
{
z=1;
for(j=0;j<n;j++)
{
if(!z)
break;
if(i+j<m)
if(a[i+j]==50&b[j]==50)
z=0;
}
if(z)
{
if(n+i>m)
x2=n+i;
if(x2<y2)
y2=x2;
}
}
if(y2>y1)
printf("%d\n",y1);
else
printf("%d\n",y2);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

也是下午上课时看书有的思路,交了2次,第一次数组1000,开小了,RE了一次。第二次怒开100000,Ac了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <string.h>
#define maxn 100000
int main()
{
int i,j,m,n,x,y,z;
char a[maxn];
char b[maxn];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
while(scanf("%s%s",a,b)!=EOF)
{
x=1;
z=0;
m=strlen(a);
n=strlen(b);
for(i=0;i<m;i++)
{
y=1;
for(j=i+z;j<n;j++)
{
if(a[i]==b[j])
{
y=0;
break;
}
z++;
}
if(y)
{
x=0;
break;
}
}
if(x)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

下午上Acm课看不清投影,就看了了看书,这道题感觉还能简单点,就回来先做了,交了三次Ac的,第一次是忽略了第一个长方形的长宽不在后来的循环里,没有进行大小交 换,第二次是没有删除调试用的输出数组b值的语句。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <string.h>
int main()
{
int i,j,temp,k,l,x,count;
int a[6][2];
int b[6];
int c[6][2];
while(scanf("%d%d",&a[0][0],&a[0][1])!=EOF)
{
if(a[0][0]>a[0][1])
{
temp=a[0][0];
a[0][0]=a[0][1];
a[0][1]=temp;
}
x=1,count=0;
memset(b,0,sizeof(b));
c[0][0]=c[0][1]=0;
for(i=1;i<6;i++)
{
scanf("%d%d",&a[i][0],&a[i][1]);
c[i][0]=c[i][1]=0;
if(a[i][0]>a[i][1])
{
temp=a[i][0];
a[i][0]=a[i][1];
a[i][1]=temp;
}
}
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
for(k=0;k<2;k++)
{

if(a[i][k]==a[j][0]&&i!=j)
c[i][k]++;
if(a[i][k]==a[j][1]&&i!=j)
c[i][k]++;
}
if(a[i][0]==a[j][0]&&a[i][1]==a[j][1]&&i!=j)
b[i]++;
}
if(a[i][0]==a[i][1])
count++;
}
if(count==0&&b[0]==5)
x=0;
if(count>2&&c[0][0]!=10)
x=0;
for(i=0;i<6;i++)
{
if(!x)
goto END;
if(!b[i])
x=0;
for(j=0;j<2;j++)
if(c[i][j]<3)
x=0;
}
END:
if(x)
printf("POSSIBLE\n");
else
printf("IMPOSSIBLE\n");
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

前天看的题,写好了输入片段,昨天写入党申请书没做题,今天才做完,题目也不是很难,思路挺好想的。交了三次才Ac。第一次没有注意相同时要字典序最小。

第二次是因为在输出时在后面加上了空格,但从样例看,输出应该是带空格的。看了好久不知道哪错了,第三次索性去了空格交上去,反而过了,也不知道是怎么回事。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <string.h>
#define maxm 60
#define maxn 1050
int main()
{
char a[maxm][maxn];
int b[4][maxn];
int i,j,m,n,T,count;
scanf("%d\n",&T);
while(T--)
{
scanf("%d %d\n",&m,&n);
for(i=0;i<4;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=0;
}
}
for(i=0;i<m;i++)
{
scanf("%s",a[i]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]=='A')
b[0][j]++;
else if(a[i][j]=='C')
b[1][j]++;
else if(a[i][j]=='G')
b[2][j]++;
else if(a[i][j]=='T')
b[3][j]++;
}
}
count=0;
for(i=0;i<n;i++)
{
if(b[0][i]>=b[1][i]&&b[0][i]>=b[2][i]&&b[0][i]>=b[3][i])
{
printf("A");
count+=b[0][i];
}
else if(b[1][i]>=b[0][i]&&b[1][i]>=b[2][i]&&b[1][i]>=b[3][i])
{
printf("C");
count+=b[1][i];
}
else if(b[2][i]>=b[0][i]&&b[2][i]>=b[1][i]&&b[2][i]>=b[3][i])
{
printf("G");
count+=b[2][i];
}
else if(b[3][i]>=b[0][i]&&b[3][i]>=b[1][i]&&b[3][i]>=b[2][i])
{
printf("T");
count+=b[3][i];
}
}
printf("\n%d\n",m*n-count);
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

跟227一样,也是昨晚看书时就有了思路,今天下午开始做的,建了a,b两个数组,a用来存放输入的内容,b用来判断是否为起始格或'*',最后输出。输出时,编号用 的是%3d差点忽略了,最后提交又差点忘删除文件重定向语句。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <string.h>
#define maxn 20
int main()
{
char a[maxn][maxn];
int b[maxn][maxn];
int m,n,i,j,count,x=1,y,first=1;
while(1)
{
count=0;
scanf("%d",&m);
if(!m)
goto END;
if(first)
first=0;
else
printf("\n");
scanf("%d\n",&n);
for(i=0;i<m;i++)
{
for(j=0;j<n+1;j++)
{
a[i][j]=getchar();
}
}
for(i=0;i<maxn;i++)
{
for(j=0;j<maxn;j++)
{
b[i][j]=0;
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]!='*')
{
if(!i||!j)
{
b[i][j]=++count;
}
else if(a[i-1][j]=='*'||a[i][j-1]=='*')
{
b[i][j]=++count;
}
}
else
b[i][j]=-1;
}
}
printf("puzzle #%d:\n",x++);
printf("Across\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(b[i][j]>0)
{
if(!j||b[i][j-1]==-1)
{
printf("%3d.",b[i][j]);
y=j;
while(a[i][y]!='*'&&y<n)
{
printf("%c",a[i][y]);
y++;
}
printf("\n");
}
}
}
}
printf("Down\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(b[i][j]>0)
{
if(!i||b[i-1][j]==-1)
{
printf("%3d.",b[i][j]);
y=i;
while(a[y][j]!='*'&&y<m)
{
printf("%c",a[y][j]);
y++;
}
printf("\n");
}
}
}
}
}
END:
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

昨天晚自习看的题目,马上就有思路了,建一个二维数组然后根据输入的字符交换。晚自习结束之后,因为最近熬夜有点多,回来就睡了。今天早上开始打的,中途因为对get char的用法不是很了解,而且输入移动方法时会有“”,处理不好所以卡住了好久。最后提交时,忘了删文件重定向输入语句了,RE了一次,看了好久都没检查出来, 以后要避免出现这种情况。

这是最后Ac的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <stdio.h>
#include <string.h>
#define maxn 10000
#define max 10
int main()
{
char a[max][max];
char s[maxn];
int n,i,j,l,x,y,z,temp,first=1,count=1;
while(1)
{
z=1;
for(i=0;i<5;i++)
{
for(j=0;j<6;j++)
{
a[i][j]=getchar();
if(a[i][j]==' ')
x=i,y=j;
if(a[i][j]=='Z')
goto END;
}
}
for(i=0;;i++)
{
s[i]=getchar();
if(s[i]=='\n')
s[i]=getchar();
if(s[i]=='0')
{
getchar();
break;
}
}
n=strlen(s);
for(i=0;i<n;i++)
{
if(!z)
break;
if(s[i]=='A')
{
if(!x)
{
z=0;
break;
}
a[x][y]=a[x-1][y];
a[x-1][y]=' ';
x--;
}
else if(s[i]=='B')
{
if(x==4)
{
z=0;
break;
}
a[x][y]=a[x+1][y];
a[x+1][y]=' ';
x++;
}
else if(s[i]=='L')
{
if(!y)
{
z=0;
break;
}
a[x][y]=a[x][y-1];
a[x][y-1]=' ';
y--;
}
else if(s[i]=='R')
{

if(y==4)
{
z=0;
break;
}
a[x][y]=a[x][y+1];
a[x][y+1]=' ';
y++;
}
else if(s[i]=='0')
break;
else
z=0;
}
if(z)
{
if(first)
first=0;
else
printf("\n");
printf("Puzzle #%d:\n",count);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(j)
printf(" %c",a[i][j]);
else
printf("%c",a[i][j]);
}
printf("\n");
}
count++;
}
else
{
if(first)
first=0;
else
printf("\n");
printf("Puzzle #%d:\n",count);
printf("This puzzle has no final configuration.\n");
count++;
}
}
END:
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

昨天上午开始写的,后来遇到了问题,RE了两次,就一直没做,今天Ac了455之后,换了个思路,把这个Ac了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include <string.h>
#define maxn 40000
int main ()
{
int n,t,i,j,count,first;
char a[maxn];
int b[10][2]={0};
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
count=0;
first=1;
for(i=0;i<10;i++)
{
b[i][0]=i;
b[i][1]=0;
}
scanf("%d",&n);
if(n>=10)
{
for(i=1;i<10;i++)
{
a[count]=i+48;
count++;
}
if(n>=100)
{
for(i=10;i<100;i++)
{
a[count]=i/10+48;
count++;
a[count]=i%10+48;
count++;
}
if(n>=1000)
{
for(i=100;i<1000;i++)
{
a[count]=i/100+48;
count++;
a[count]=(i%100)/10+48;
count++;
a[count]=i%10+48;
count++;
}
for(i=1000;i<n+1;i++)
{
a[count]=i/1000+48;
count++;
a[count]=(i%1000)/100+48;
count++;
a[count]=(i%100)/10+48;
count++;
a[count]=(i%10)+48;
count++;
}
}
else
{
for(i=100;i<n+1;i++)
{
a[count]=i/100+48;
count++;
a[count]=(i%100)/10+48;
count++;
a[count]=i%10+48;
count++;
}
}
}
else
{
for(i=10;i<n+1;i++)
{
a[count]=i/10+48;
count++;
a[count]=i%10+48;
count++;
}
}
}
else
for(i=1;i<n+1;i++)
{
a[count]=i+48;
count++;
}
for(i=0;i<10;i++)
{
for(j=0;j<maxn;j++)
{
if(!a[j])
break;
if(b[i][0]==a[j]-48)
b[i][1]++;
}
}
for(i=0;i<10;i++)
{
if(first)
{
printf("%d",b[i][1]);
first=0;
}
else
printf(" %d",b[i][1]);
}
printf("\n");
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

今天帮人Debug,实在看不懂他写的什么,就重写了一份给他。感觉学了这么久之后,再写这种水题轻松加随意,写得也比之前的好了。

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<string.h>
int t;
char s[90];
int main(){
scanf("%d",&t);
while(t--){
scanf("%s",s);
int i,n=(int)strlen(s);
for(i=1;i<n;++i){
if(n%i) continue;
int ok=1,j=0,k=0;
for(;j<n&&ok;k%=i)
if(s[j++]!=s[k++]) ok=0;
if(ok) break;
}
printf("%d\n",i);
if(t) printf("\n");
}
return 0;
}

从昨天晚上开始做的,今天终于Ac了。题目是让输出输入的字符串的最小周期。开始使用了数组,当字符长度为n时,i从n-1开始自减,n%i=0时,建立数组a[ i][ n/i ];判断数组中对应值是否相等来输出i。可总是出问题,于是后来放弃数组,改为用j%i表示昨天数组中对应的值,并且使用x,y两个变量来限制多余的循 环,提交一次就Ac了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <string.h>
#define maxn 100
int main()
{
int T,n,i,j,x,y;
scanf("%d",&T);
char s[maxn];
while(T--)
{
y=0;
scanf("%s",s);
n=strlen(s);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
x=1;
for(j=i;j<n;j++)
{
if(x==0)
break;
if(s[j]!=s[j%i])
x=0;
}
if(x)
y=i;
}
if(y)
break;
}
if(T)
printf("%d\n\n",y);
else
printf("%d\n",y);
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **

今天第一次去机房刷题,下了编程课就去了,在机房刷完了作业之后,开始做1225,RE了2次,就开始看书了,后来问学长例题也做,就把例题打了,代码书上都有,书上 使用了getchar进行录入,之前像这种情况我一直用gets,看了书才知道gets在C11中被删了,以后尽量不使用gets。感觉q=1和循环体中q=!q,很 精妙,如果我自己写可能会设变量count计数,然后通过判断count%2的值来输出左引号或右引号。以后书上的例题不发博客了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>  
int main()
{
int c,q=1;
while((c=getchar())!=EOF)
{
if(c=='"')
{
printf("%s",q?"``":"''");
q=!q;
}
else
printf("%c",c);
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **