#include<stdio.h> #include<stdio.h> #include<string.h> intgetLength(charstring[]) { int result = 0; for (int i = 0; string[i] != '\0'; i++) result++; return result - 1; } intmain() { int status, g = 0; char domString[30] = {'\0'}; char subString[30] = {'\0'}; gets(domString); gets(subString); int lengthDom = strlen(domString); int lengthSub = strlen(subString);
for (int i = 0; i < lengthDom; i++) { status = 1; for (int j = 0; j < lengthSub; j++) { if (domString[i + j] == subString[j]) status *= 1; else status *= 0; } if (status) { printf("%d ", i + 1); g++; } } if (!g) printf("No!"); return0; }
#include<iostream> #include<cmath> intisPrime(int n) { if (n == 2 || n == 3) returntrue; for (int i = 2; i * i <= n; i++) if (!(n % i)) returnfalse; returntrue; }
intmain() { int n, m; scanf("%d", &n); m = (int)pow(2, n) - 1; printf("%d %d\n", m, isPrime(m)); return0; }
啥?为什么用C++的库?因为用C语言的库时,编译器不认pow函数,认为
1 2 3 4 5 6 7 8 9 10 11 12 13
用于 x86 的 Microsoft (R) C/C++ 优化编译器 18.00.21005.1 版版权所有(C) Microsoft Corporation。 保留所有权利。
cl: 命令行 warning D9035 :“o”选项已否决,并将在将来的版本中移除 xdoj682.c xdoj682.c(18) : error C2668: “pow”: 对重载函数的调用不明确 C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\include\math.h(1233): 可能是“longdoublepow(longdouble,int)throw()” C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\include\math.h(1231): 或 “longdoublepow(longdouble,longdouble)throw()” C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\include\math.h(1117): 或 “floatpow(float,int)throw()” C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\include\math.h(1115): 或 “floatpow(float,float)throw()” C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\include\math.h(1027): 或 “doublepow(double,int)throw()” C:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\include\math.h(512): 或 “doublepow(double,double)” 尝试匹配参数列表“(int, int)”时