Compile Error
/in/foo.cc: In function 'int main()': /in/foo.cc:16:39: error: 'ans' was not declared in this scope cout<<"The 1500'th ugly number is "<<ans<<"."<<endl; ^~~
代码
#include<bits/stdc++.h>
using namespace std;
int a=1,b=1,c=1,f[1501]={0,1},tmp;
int main(){
ios::sync_with_stdio(false);
for(int i=2;i<=1500;i++){
tmp=min(min(2*f[a],3*f[b]),5*f[c]);
f[i]=tmp;
if(tmp==2*f[a])
a++;
if(tmp==3*f[b])
b++;
if(tmp==5*f[c])
c++;
}
cout<<"The 1500'th ugly number is "<<ans<<"."<<endl;
return 0;
}