第一题 语言大师
我在考试的时候
发现我的 c n t cnt cnt根本不会++
后面才发现printf放错地方了额
因为把printf放在循环里面只会更新一次就是当 l a = = 1 la == 1 la==1
c n t = 1 cnt = 1 cnt=1
之后 c n t > = 2 cnt >= 2 cnt>=2的时候,他就不会更新了。。
然后就没有然后了
30分代码
#include <cstdio>
using namespace std;
int l, k ,cnt;
int main(){
scanf("%d %d",&k, &l);
for(int i = 1;i <= l;i++){
if(l % k == 0){
l /= k, cnt++;
printf("YES\n");
printf("%d",cnt);
return 0;
}
else{
printf("NO");
return 0;
}
}
return 0;
}
AC代码(无奈)
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int l,k,cnt;
int main() {
//freopen("language.in","r",stdin);
//freopen("language.out","w",stdout);
scanf("%d %d",&k,&l);
while(l != 1) {
if(l % k == 0)
l /= k,cnt ++;
else
return! printf("NO");
}
printf("YES\n%d",cnt - 1);
return 0;
}