1. In a N * N matrix, it is determined whether there is the diagonal element
used:
for(int i = 1; i <= n; i++){
for(int j = i+1; j <= n; j++){
if(abs(i-j) == abs(P[i]-P[j])){
flag = false;
}
}
}
2. The input and output, on floating-point format
in scanf float is% f can, but must% lf double
in two possible are used printf% f
There is output format
printf ( "% m.nf");
represents a total of m bits, n bits after the decimal point, m is a decimal digit, sign bit
while a right-aligned +
- represented Left
2019/10/30 11:57
//1.关于String中的find函数
头文件:
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
<1>返回查找字符的首字母下标
string s1 = "qwer";
string s2 = "er";
int index = s1.find(s2);
如果没有找到,就会返回nops
if(index == string::nops){
printf("没有找到该字符串!");
}
<2>返回子串出现在母串中的首次出现位置和最后一次出现的位置
int index = s1.find_first_of(s2);
int index = s1.find_last_of(s2);
<3>查找某一给定位置的子串位置
表示从字符串s1下标5开始查找,然后返回在s中的下标
int index = s1.find(s2,5)
<4>查找所有子串在母串中出现的位置
//查找s 中flag 出现的所有位置。
flag="a";
position=0;
int i=1;
while((position=s.find(flag,position))!=string::npos)
{
cout<<"position "<<i<<" : "<<position<<endl;
position++;
i++;
}
<5>反向查找子串在母串中出现的位置
int index = s1.rfind(s2);