Last active
December 10, 2015 23:38
-
-
Save alphaKAI/4510517 to your computer and use it in GitHub Desktop.
4文字のやつをよくわかんないけど OpenMPつかって2スレッドでやってみた(できてるかしらんけど)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <omp.h> | |
//GPL v3 LICENSE http://www.gnu.org/licenses/gpl.html | |
//Copyright (C) α改 @alpha_kai_NET 2012-2013 alpha-kai-net.info all rights reserved | |
//全件検索したいn文字IDのnのとこ | |
#define SID 4 | |
int ReturnStrings(const char* path, const int num, char* buf, const int size); | |
int main(void){ | |
int i; | |
//abcdefghijklmnopqrstuvexyz01234567_ | |
char strset[38] = {'\0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','_'}; | |
char str[1000000]; | |
//char *str; | |
char str2[1000000]; | |
char cmd[1000000]; | |
char file[1000000]; | |
char baseurl[]= "https://twitter.com/users/username_available?username="; | |
char basefile[]="username_available?username="; | |
int sss; | |
int get_line; | |
int return_sum; | |
char rmcmd[]="rm username_available?username=*"; | |
int acts; | |
int rp2; | |
int cut; | |
FILE *fp; | |
acts=1; | |
//n^r n=(abcdefghijklmnopqrstuvexyz01234567_)=>37 r=4 37^4=1874161 | |
//個数計算 | |
cut=37; | |
for(rp2=1;rp2<=SID-1;rp2++){ | |
cut*=37; | |
} | |
//omp_set_num_threads(2); | |
#pragma omp parallel | |
{ | |
for(i=1;i<=cut;i++){ | |
sprintf(str,"%c%c%c%c", strset[rand()%38], strset[rand()%38], strset[rand()%38], strset[rand()%38]); | |
//str="8tq6"; | |
sprintf(cmd, "wget %s%s >/dev/null 2>&1",baseurl ,str); | |
sss=system(cmd); | |
sprintf(file, "%s%s",basefile ,str); | |
return_sum = ReturnStrings(file, 1, str2, 1000000); | |
if(strstr(str2,"true")!=NULL){ | |
fp=fopen("result.txt","ab"); | |
fprintf(fp,"%s\n", str); | |
fclose(fp); | |
printf("@%s 取得可能\a\t発見済み取得可能件数/%d文字ID全件 => %d/%d\n", str, SID, acts, cut); | |
printf("現状表示%d/%d\n",i,cut); | |
//ビープ音 | |
printf("\a"); | |
acts++; | |
} | |
// printf("%s\n",file); | |
sss=system(rmcmd); | |
} | |
}//並列処理ブロック | |
return 0; | |
} | |
int ReturnStrings(const char* path, const int num, char* buf, const int size){ | |
int cnt = 0; | |
FILE* file = NULL; | |
if ((file = fopen(path, "r")) == NULL) | |
return -1; | |
//ファイルチェック失敗 | |
while (fgets(buf, size, file) != NULL && num > ++cnt); | |
fclose(file); | |
if (num != cnt) | |
{ | |
for (cnt = 0; cnt < size; ++cnt) | |
buf[cnt] = 0; | |
return -2; | |
//データ取得失敗 | |
} | |
//文字列の最後にNULL文字つける | |
strcat(buf, "\0"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment