集訓第二週

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\n",data[1]);
 return 0;
}

7:編程的幾個原則。

1)代碼重用原則。你的代碼儘量能引用的地方多。

2)避免重複原則。一個代碼儘量簡單,重複使用。

3)低耦合原則。一段代碼儘量不要使用共享參數。

發佈了21 篇原創文章 · 獲贊 13 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章