Hello World! UVA - 11636(打表)

 刚开始忽略了N=1这种情况,所以WA了,

#include
using namespace std;
int idx[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384};
int main()
{
    int N, kcases = 0;
    while(cin >> N && N >= 0)
    {
        for(int i = 0; i < 15; i++)
        {
            if(N <= idx[i])
            {
                cout << "Case " << ++kcases << ": " << i << endl;
                break;
            }
        }
    }
    return 0;
}

 

你可能感兴趣的:(刘汝佳的算法竞赛入门经典)