集训第二周

1:当题目中有0,1循环判断时,想着用!运算,

  例如Tex括号。

2:当牵扯方向的移动时,用数组来模拟;

  int a[4]={0,0,1,-1},b[4]={-1,1,0,0};

  for(i=0;i<4;i++)
  {
    ch[x+a[i]][y+b[i]];  
  }
3:最小周期串的找法简单核心代码

  if(word[j] != word[j%i])

  {ok=0;break;}

4:两个数相加一共进了多少次位(整形上限大约是2000000000);

  for(i=10;i>=0;i--)

  {

    c=(a%10+b%10+c) >9 ?1:0;

    ans+=c;

    a/=10;b/=10;

  }

5:memse函数是用来对一段内存空间全部设置为某个字符,一般用在对定义的字符串进行初始化

  memset可以方便的清空一个结构类型的变量或数组。

如:
struct sample_struct
{
char csName[16];
int iSeq;
int iType;
};

对于变量
struct sample_strcut stTest;

一般情况下,清空stTest的方法:
stTest.csName[0]='/0';
stTest.iSeq=0;
stTest.iType=0;

用memset就非常方便:
memset(&stTest,0,sizeof(struct sample_struct));

如果是数组:
struct sample_struct TEST[10];

memset(TEST,0,sizeof(struct sample_struct)*10);

6:字符串与数字相对应的代码

还可以实现整数整数的对应,尤其是在那种一些数出现过几次的时候。

#include <iostream>
#include<map>
#include<string>
using namespace std;
map<string,int>STL;
int main()
{
 int i,j,k,n,data[50],c;
 char a[50],b[50];
 for(i=1;i<=5;i++)
 {
  scanf("%s",a);
  STL[a]=i;
 }
 scanf("%s %d",b,&c);
 data[STL[b]]=c;
 printf("%d ",data[1]);
 return 0;
}

7:字母A到Z每个出现过的个数,可以用一位数组来计数,a[c-'A'];

每个是否出现可以用可以用true or false;

原文地址:https://www.cnblogs.com/liun1994/p/3256761.html