1.2
#include <iostream>
#include <stdio.h>
#include <vector>
#include <iterator>
#include <stdlib.h>
using namespace std;
char arr[20][20];
char words[30][4]={
"boy","own","sad","job","dry",
"can","may","bed","age","air",
"ace","act","add","eye","ago",
"any","arm","bad","beg","bid",
"big","bit","box","but","bug",
"but","cop","cut","cry","dam"
};
void init(){
srand(NULL);
cout << "all characters"<< endl;
for(int i =0;i < 20;i ++){
for(int j = 0;j < 20;j ++){
arr[i][j] = rand() % 26 + 97;
printf("%c ",arr[i][j]);
}
cout << endl;
}
cout << "end"<< endl;
cout <<"start print words"<< endl;
for(int i =0;i < 30;i ++){
printf("%4s",words[i]);
if((i + 1) % 5 == 0){
cout << endl;
}
}
cout << "end print words"<< endl;
}
struct node{
int hang;
int lie;
int chang;
int direction;
};
void f1(){
vector<node> v1;
node n;
for(int i = 0;i < 20;i ++){
for(int j = 0;j < 20;j ++){
for(int k = 0;k < 30;k ++){
if(j < 18){
if(arr[i][j] == words[k][0] && arr[i][j+1]==words[k][1] && arr[i][j+2]==words[k][2]){
n.hang = i;
n.lie = j;
n.direction = 1;
n.chang = 3;
v1.push_back(n);
}
}
if(j >1){
if(arr[i][j]==words[k][0] && arr[i][j-1]==words[k][1] && arr[i][j-2]==words[k][2]){
n.hang = i;
n.lie = j;
n.chang = 3;
n.direction = 2;
v1.push_back(n);
}
}
if(i <18){
if(arr[i][j]==words[k][0] && arr[i+1][j]==words[k][1] && arr[i+2][j]== words[k][2]){
n.hang = i;
n.lie = j;
n.chang = 3;
n.direction = 3;
v1.push_back(n);
}
}
if(i > 1){
if(arr[i][j]==words[k][0] && arr[i-1][j]==words[k][1] && arr[i-2][j]==words[k][2]){
n.hang = i;
n.lie = j;
n.direction = 4;
n.chang = 3;
v1.push_back(n);
}
}
if(((i+2) < 20) && ((j+2) < 20) ){
if(arr[i][j]==words[k][0] && arr[i+1][j+1]==words[k][1] && arr[i+2][j+2]==words[k][2]){
n.hang = i;
n.lie = j;
n.chang = 3;
n.direction == 5;
v1.push_back(n);
}
}
if(i >1 && j < 18){
if(arr[i][j]==words[k][0] && arr[i+1][j-1]==words[k][1] && arr[i+2][j-2]==words[k][2]){
n.hang = i;
n.lie = j;
n.chang = 3;
n.direction = 6;
v1.push_back(n);
}
}
if(i >1 && j >1){
if(arr[i][j]==words[k][0] && arr[i-1][j-1]==words[k][1] && arr[i-2][j-2]==words[k][2]){
n.hang = i;
n.lie = j;
n.chang = 3;
n.direction = 7;
v1.push_back(n);
}
}
if(i < 18 && j >1){
if(arr[i][j]==words[k][0] && arr[i+1][j-1]==words[k][1] && arr[i+2][j-2]==words[k][2]){
n.hang = i;
n.lie = j;
n.direction = 8;
v1.push_back(n);
}
}
}
}
}
for(unsigned i = 0;i < v1.size();i ++){
cout << "hang: " << v1[i].hang <<
"lie : " << v1[i].lie <<
"chang : " << v1[i].chang <<
"direction: " << v1[i].direction << endl;
}
}
int main(){
init();
f1();
return 0;
}
1.7
1.8 2的100次方模5为1
2^4 = 16 = (n*10 + 6)
2^100 = (2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4)*(2^4) = (N*10 +6)
原文地址:http://www.cnblogs.com/demps/p/3793035.html