class COIN
{
public:
COIN(int n1,int k1){
n = n1
k = k1
a = new int[n]
for(int i = 0i <n i++){
a[i] = 1
}
}
~COIN(){
delete []a
}
void fun(){
int i = 0
for(int j = 1 j <= k j++){
i = (j - 1) % n//写为 i = j%n 亦可
if( ! ( j % 3) ){
a[i] = 1 - a[i]
continue
}
if( ! (j % 5)){
a[i] = 1 - a[i]
continue
}
}
}
void print(){
int i
for(i = 0 i <n - 1 i ++){
printf("%d ",a[i])
}
printf("%d\n",a[i])
}
private:
int * a
int n
int k
}
int main ()
{
COIN *a = new COIN(12,100)
a->fun()
a->print()
delete a
}
逻辑太混乱。。我给你重写。
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,count=0
char a[1000]
bool c[1000],d[1000]
scanf("%s",a)
for(i=0i<=strlen(a)i++)
if(a[i]=='*')
c[i]=0
else
c[i]=1
scanf("%s",a)
for(i=0i<=strlen(a)i++)
if(a[i]=='*')
d[i]=0
else
d[i]=1
for(j=0j<=ij++)
if(c[j]!=d[j])
{
d[j]=(!d[j])
d[j+1]=(!d[j+1])
count++
}
printf("%d",count)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)