BW BW

Size: px
Start display at page:

Download "BW BW"

Transcription

1 Induced Sorting BW 11T2042B

2 BW BW Induced Sorting BW Induced Sorting A 20 A.1 BW () A.2 BW () i

3 1 1.1 BW BW (BWT Burrows-Wheeler Transform) M. Burrows and D. J. Wheeler 1994 [1] Block-sorting BW BW BW Move-to-front coding( ) [1] BW BW M. Burrows [1] Induced Sorting BW [2] 3 Induced Sorting [3] BW 3 BW Induced Sorting BW BW BW BW 1

4 2.1 S N 1. S N N M M[0, 0],..., M[0, N 1] S[0],..., S[N 1] M[1, 0],..., M[1, N 2], M[1, N 1] S[1],..., S[N 1], S[0] 2. M 3. M L L[0],..., L[N 1] M[N 1, 0],..., M[N 1, N 1] 4. M S I S (L, I) S =shinshu BW (L, I) = (sshiunh,4) ( 1) M 0 s h i n s h u 1 h i n s h u s 2 i n s h u s h 3 n s h u s h i 4 s h u s h i n 5 h u s h i n s 6 u s h i n s h 1 = BW M 0 h i n s h u s 1 h u s h i n s 2 i n s h u s h 3 n s h u s h i 4 s h i n s h u 5 s h u s h i n 6 u s h i n s h (L, I) = (sshiunh,4) (L, I) S BW 1. L F M F M M i F[i] L[i] S () 2

5 2. L F L F [1] 3. (L, I) S L[I] L[I] S L[i] F F [C[i]] S[N 1] = L[I] = F [C[I]], F [C[I]] L[C[I]] S[N 2] = L[C[I]] = F [C[C[I]]],... ( 2) L = s 1 s 2 h 1 i u n h 2 F = h 1 h 2 i n s 1 s 2 u 2 u h h s... S =shinshu ( ) 2.2 BW BW he t M he t he t k BW BW ASCII BW 2.3 BW N N 2 N 3

6 S M i j S S[i] S[i + N 1 mod N] S[j] S[j + N 1 mod N] O(N log N) ( S =aaa... ) 2 N O(N 2 log N) N 3 Induced Sorting BW [2] Induced Sorting O(N) Ge Nong 2011 [3] BW Induced Sorting 3.1 BW S i S suf(s, i) 3 $ $ N Induced Sorting $ suf(s, i) S i suf(s, i) 0,..., N 1 N log N SA S[SA[i]] 2 M[i][0] 4

7 suf 0 s h i n s h u $ 1 h i n s h u $ 2 i n s h u $ 3 n s h u $ 4 s h u $ 5 h u $ 6 u $ 7 $ 3 = 7 $ suf 1 h i n s h u $ 5 h u $ 2 i n s h u $ 3 n s h u $ 0 s h i n s h u $ 4 s h u $ 6 u $ SA = ( ) BW L[i] = { S[SA[i] 1] i 0 S[N 1] i = Induced Sorting Induced Sorting 1 Type-S: suf(s, i) < suf(s, i + 1) suf(s, N 1) = $ Type-L: suf(s, i) > suf(s, i + 1) S =shinshu$ suf(s, 0) = shinshu$ > suf(s, 1) = hinshu$ suf(s, 0) Type-L suf(s, i) S[i] suf(s, i) 4 S suf(s, N 1) Type-S suf(s, i) Type-S 5

8 1. S[i] < S(i + 1) 2. S[i] = S(i + 1) suf(s, i + 1) Type-S suf(s, i) Type-L 1. S[i] > S(i + 1) 2. S[i] = S(i + 1) suf(s, i + 1) Type-L 2 Type-S suf(s, i) Type-L suf(s, j) suf(s, j) S[i] = S[j] suf(s, i) > suf(s, j) suf(s, i) suf(s, j) S[i] = S[j] = c 2 2 suf(s, i + 1) suf(s, j + 1) suf(s, i) Type-S suf(s, i) < suf(s, i + 1) suf(s, i + 1) c c 1 c suf(s, j) Type-L suf(s, j) > suf(s, j + 1) suf(s, j + 1) c c 1 c suf(s, i + 1) > suf(s, j + 1) suf(s, i) > suf(s, j) c c Type-L Type-S Type-S 3 Type-S suf(s, i) suf(s, i 1) Type-L Type- S* Type-S Type-L Type- S* Type-S ( 4) Induced Sorting Step0 : Step1 :Type-S* Step2 :Type-S* Type-L 6

9 i S[i] s h i n s h u $ Type L S* S S L S* L S* 4 Step3 :Type-L Type-S N O(N) Step1 Step2 Step1 5 Step2 Step Step2:Type-L Type-S* Type-L S $ σ bkt[c] S c σ bkt bkt[0] bkt[c 1] bkt[0] bkt[c] Type-S* SA 1 Step1 5 Step1 Type-S* SA SA SA[i] n i suf(s, n i ) suf(s, n i 1) Type-L 2 suf(s, n i 1) S[n i 1] suf(s, n i 1) S[n i 1] 5 SA SA[0] suf(s, 11) suf(s, 11 1) = suf(s, 10) L S[10] = v suf(s, 10) SA 0 suf(s, n i 1) Type S Type-L suf(s, n i 1) Type-L 5?! SA Type-L SA 7

10 O(N) Step3:Type-S Step2 Type-L Type-S Step2 SA suf(s, n i ) suf(s, n i 1) Type-S 2 suf(s, n i 1) S[n i 1] suf(s, n i 1) S[n i 1] SA Type-S suf(s, n i 1) Type-S Step3 Type-S Step2 Type-S* SA Type-S SA O(N) Step1 :Type-S* Step1 Type-S* O(N) Step1 Type-S* Induced Sorting O(N) Type-S* 4 S S* S[i] S[j] Type-S* Type-S* S[i... j] $ 5 S* S s1 s1 SA1 S =shinshuuniv$ S* hinsh, huuni, iv$, $ 4 S* 1, 2, 3, 0 s1 s1 = 1230 S* Type-S* S* 8

11 i S[i] s h i n s h u u n i v $ Step0 Type L S S S L S L L L S L S S* * * * * $ h i n s u v Step1 SA[i] Step2 SA[i] ?! ?! ?! ??! ?! ????! ?? Step3 SA[i] !? !? !?? !?? !??? ??? 5 Induced Sorting 9

12 4 S $ S* S* s1 0 s1 n1 6 s1 S n1 N/2 Type-S* 1. S Type-S* SA Type-S* SA S 2. Step2 Type-L 3. Step3 Type-S SA S* 4. s1 s1 5. S* SA Step2 6. s1 1 O(N) 6 1/2 O(N) Induced Sorting O(N) Induced Sorting BW Induced Sorting O(N log N) N log σ O(N 2 ) N S 1 1 N N/4 10

13 6 Induced Sorting S N = N/8 Type-L 0 Type-S 1 Type-S* /2 N/8 N/4 SA N 1 N log N SA ( 7) 11

14 1 S S[0] S[N] SA SA[0] Type-S* SA[N] SA SA[0] S* 1 s1[n1] 2 s1 SA[N n1] s1[n1] s1 SA (SA[0] SA[n1 1]) SA1 SA[0] SA1[n1]( ) SA1 SA[0] 1 s2[n2] 3 s2 SA[n1 n2] s2 SA2 SA[0] SA2( ) SA2[0] SA2[n2 1] s2 S* SA2 SA[0] 1 s3 : s2 S* SA2 SA2 SA[0] SA2( ) SA2 : s1 S* s1 S* SA1 2 SA1 SA[0] SA1( ) s S* SA 1 SA SA[0] SA[N] 7 (3 ) SA () bkt S σ N log σ σ bkt Induced Sorting BW BW L N 12

15 3.3 Induced Sorting Ge Nong [3] [4] BW 1 Induced Sorting 00 FF bkt c bkt[c + 1] bkt[0] SA N log N 8 1 BW BW Induced Sorting Calgary Corpus [5] 13

16 1 S S[0] S[N] SA SA[0] Type-S* SA[N] SA SA [0] S* 1 s1[n1] 2 s1 SA [N n1] s1[n1] SA1 SA[0] SA1[n1]( ) SA1 SA [0] 1 s2[n2] 3 s2 SA [n1 n2] s2 SA2 SA[0] SA2( ) SA2 SA [0] 1 s3 : 2 SA1 SA[0] SA1( ) SA2 SA1 1 SA SA[0] SA[N] 8 (3 ) 4.1 Calgary Corpus [5] 18 Induced Sorting BW Induced Sorting O(N)

17 1 2 = 100[%] book1( ), obj2(), pic() (book1) 10 - (book1) 11 - (obj2) 12 - (obj2) - book , obj , pic pic Calgary Corpus ( ) pic pic 87.1[%] 00 15

18 13 - (pic) 14 - (pic) Induced Sorting Type-S* - obj2 0[%] 0.27[%] book1 pic 1 N book1 N = obj2 6 pic N = N = book pic pic 4 5 N = ( 4) 0.23[%] N ( 5) 0.056[%] book ( 15 18) 16

19 15 - ( 3) 16 - ( 4) 17 - ( 5) 18 - ( 6) 19-17

20 ( ) obj [µs] 344[µs] 2 1[µs] 0.29[%] - ( 19) [%] 5 Induced Sorting BW Induced Sorting Induced Sorting Induced Sorting Induced Sorting O(N) [1] M. Burrows and D. J. Wheeler, A Block-sorting Lossless Data Compression Algorithm, SRC Research Report 124, Digital Systems Research Center, [2] [3] Ge Nong, Sen Zhang, and Wai Hong Chan, Two Efficient Algorithms for Linear Time 18

21 Suffix Array Construction, IEEE Trans. on Computers, vol. 60, no.10, pp , Oct [4] 20Efficient%20Algorithms%20for%20Linear%20Time%20Suffix%20Array% 20Construction.pdf&can=2&q=, [5] Archive Comparison Test,

22 A A.1 BW () #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> unsigned char mask[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; // t[i] #define tget(i) ( (t[(i)/8]&mask[(i)%8])? 1 : 0 ) // (Type-L 0,Type-S 1) #define tset(i, b) t[(i)/8]=(b)? (mask[(i) % 8] t[(i) / 8]): ((~mask[(i) % 8])&t[(i) / 8]) #define chr(i) (cs==sizeof(int)? ((int*)s)[i]: ((unsigned char *)s)[i]) #define islms(i) (i>0 && tget(i) &&!tget(i-1)) // void getbuckets(unsigned char *s, int *bkt, int n, int K, int cs, bool end) { int i, sum = 0; // for (i = 0; i <= K; i++){ bkt[i] = 0; // c bkt[c+1] (bkt[0] $ 1 ) for (i = 0; i < n - 1; i++){ bkt[chr(i) + 1]++; bkt[0] = 1; // (end = false) bkt[i] bkt[0],...,bkt[i-1] // (end = true) bkt[i] bkt[0],...,bkt[i] // c bkt[c+1] bkt[c+1]-1 for (i = 0; i <= K; i++){ sum += bkt[i]; bkt[i] = end? sum : sum - bkt[i]; } // Type-L void inducesal(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n, int K, int cs, bool end) { int i, j; // getbuckets(s, bkt, n, K, cs, end); for (i = 0; i < n; i++) { j = SA[i] - 1; if (j >= 0 &&!tget(j)){ SA[bkt[chr(j) + 1]++] = j; } // Type-S void inducesas(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n, int K, int cs, bool end) { int i, j; // getbuckets(s, bkt, n, K, cs, end); for (i = n - 1; i >= 0; i--) { j = SA[i] - 1; if (j >= 0 && tget(j)){ SA[--bkt[chr(j) + 1]] = j; } // K ( $ ) n s SA (Induced Sorting) // s[n-1]=0 ( $ ) n>=2 20

23 void SA_IS(unsigned char *s, int *SA, int n, int K, int cs, int* depth) { // 1 unsigned char *t = (unsigned char *)malloc(n / 8 + 1); if (*t == NULL){ printf(" (%d)\n", LINE ); return; int i, j; // tset(n - 2, 0); // $ Type-L tset(n - 1, 1); // $ Type-S for (i = n - 3; i >= 0; i--){ tset(i, (chr(i) < chr(i + 1) (chr(i) == chr(i + 1) && tget(i + 1) == 1))? 1 : 0); // s1 // int *bkt = (int *)malloc(sizeof(int)*(k + 1)); if (*bkt == NULL){ printf(" (%d)\n", LINE ); return; // getbuckets(s, bkt, n, K, cs, true); // SA -1 for (i = 0; i < n; i++){ SA[i] = -1; // $ n-1 SA[--bkt[chr(n - 1)]] = n - 1; // s[i] Type-S* s[i] i for (i = 1; i < n - 2; i++){ if (islms(i)){ SA[--bkt[chr(i) + 1]] = i; // Type-L Type-S inducesal(t, SA, s, bkt, n, K, cs, false); inducesas(t, SA, s, bkt, n, K, cs, true); free(bkt); // SA n1 Type-S* // n1 n int n1 = 0; for (i = 0; i < n; i++){ if (islms(sa[i])){ SA[n1++] = SA[i]; // S* // SA[n1],...,SA[n-1] for (i = n1; i < n; i++){ SA[i] = -1; // S* int name = 0, prev = -1; for (i = 0; i < n1; i++) { int pos = SA[i]; bool diff = false; // S[pos] S[prev] for (int d = 0; d<n; d++){ // 2 S* if (prev == -1 chr(pos + d)!= chr(prev + d) tget(pos + d)!= tget(prev + d)){ diff = true; break; // d s[pos+d]=s[prev+d] Type-S* // 2 S* else if (d>0 && (islms(pos + d) islms(prev + d))){ break; 21

24 // 2 S* ( ) // name S* if (diff) { name++; prev = pos; // SA[n1] SA[n-1] S* s pos = (pos % 2 == 0)? pos / 2 : (pos - 1) / 2; SA[n1 + pos] = name - 1; // S* SA[n-1-n1] SA[n-1] s1 for (i = n - 1, j = n - 1; i >= n1; i--){ if (SA[i] >= 0) SA[j--] = SA[i]; // // s1 int *SA1 = SA, *s1 = SA + n - n1; // name n1 if (name < n1){ *depth += 1; SA_IS((unsigned char*)s1, SA1, n1, name, sizeof(int), depth); // name n1 S*s1 else { for (i = 0; i < n1; i++){ SA1[s1[i]] = i; // s1 s SA // bkt = (int *)malloc(sizeof(int)*(k + 1)); if (*bkt == NULL){ printf(" (%d)\n", LINE ); return; // Type-S* // getbuckets(s, bkt, n, K, cs, true); // s1 S* s for (i = 1, j = 0; i < n; i++){ if (islms(i)){ s1[j++] = i; // s1 s s S* s S* for (i = 0; i < n1; i++){ SA1[i] = s1[sa1[i]]; // SA for (i = n1; i < n; i++){ SA[i] = -1; // S* for (i = n1-1; i >= 0; i--) { j = SA[i]; SA[i] = -1; if (i == 0){ SA[--bkt[chr(j)]] = j; else{ SA[--bkt[chr(j) + 1]] = j; // Type-S*Type-L Type-S inducesal(t, SA, s, bkt, n, K, cs, false); inducesas(t, SA, s, bkt, n, K, cs, true); 22

25 free(bkt); free(t); } // ( BW ) // int main(int argc, char *argv[]){ int size = atoi(argv[2]); // BW unsigned char* s = (unsigned char*)malloc(size); int* sa = (int*)malloc(sizeof(int)*size); unsigned char* L = (unsigned char*)malloc(size); if ((s == NULL) (sa == NULL) (L == NULL)){ printf(" (%d)\n", LINE ); return 0; int dep; int I; // size-1 $ FILE *fp = fopen(argv[1], "rb"); if (fp == NULL){ printf("open error\n"); return -1; if (fread(s, sizeof(char), size - 1, fp) < size - 1){ printf("size error\n"); return -1; fclose(fp); s[size - 1] = \0 ; // Induced Sorting s dep = 1; SA_IS(s, sa, size, 256, sizeof(char), &dep); // s BW L I int i; for (i = 0; i < size; i++){ if (sa[i] == 0){ L[i] = s[size - 1]; I = i; else{ L[i] = s[sa[i] - 1]; /* printf("\n SA =\n"); for (i = 0; i < size; i++){ printf("%d ", SA[i]); printf("\n"); printf("\n L =\n"); for (i = 0; i < size; i++){ printf("%02x ", L[i]); printf("\n"); */ /* FILE *fp1 = fopen("outsa1.txt", "wb"); if (fp1 == NULL){ printf("open error\n"); return -1; fwrite(sa, sizeof(char), size, fp1); fclose(fp1); */ 23

26 FILE *fp2 = fopen("outl.txt", "wb"); if (fp2 == NULL){ printf("open error\n"); return -1; fwrite(l, sizeof(char), size, fp2); fclose(fp2); FILE *fp3 = fopen("outi.txt", "wt"); if (fp3 == NULL){ printf("open error\n"); return -1; fprintf(fp3, "%d", I); fclose(fp3); free(s); free(sa); free(l); return 0; } A.2 BW () #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> unsigned char mask[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; #define tget(i) ( (t[(i)/8]&mask[(i)%8])? 1 : 0 ) #define tset(i, b) t[(i)/8]=(b)? (mask[(i) % 8] t[(i) / 8]): ((~mask[(i) % 8])&t[(i) / 8]) #define chr(i) (cs==sizeof(int)? ((int*)s)[i]: ((unsigned char *)s)[i]) #define islms(i) (i>0 && tget(i) &&!tget(i-1)) // void getbuckets(unsigned char *s, int *bkt, int n, int K, int cs, bool end) { int i, sum = 0; for (i = 0; i <= K; i++){ bkt[i] = 0; for (i = 0; i < n - 1; i++){ bkt[chr(i) + 1]++; bkt[0] = 1; for (i = 0; i <= K; i++){ sum += bkt[i]; bkt[i] = end? sum : sum - bkt[i]; } // Type-L void inducesal(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n, int K, int cs, bool end) { int i, j; getbuckets(s, bkt, n, K, cs, end); for (i = 0; i < n; i++) { j = SA[i] - 1; if (j >= 0 &&!tget(j)){ SA[bkt[chr(j) + 1]++] = j; } // Type-S void inducesas(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n, int K, int cs, bool end) { int i, j; getbuckets(s, bkt, n, K, cs, end); for (i = n - 1; i >= 0; i--) { 24

27 j = SA[i] - 1; if (j >= 0 && tget(j)){ SA[--bkt[chr(j) + 1]] = j; } // s SA (Induced Sorting) void SA_IS(unsigned char *s, int *SA,int *SAC, int n, int K, int cs, bool *bottom, int *depth) { unsigned char *t = (unsigned char *)malloc(n / 8 + 1); if (*t == NULL){ printf(" (%d)\n", LINE ); return; int i, j; tset(n - 2, 0); tset(n - 1, 1); for (i = n - 3; i >= 0; i--){ tset(i, (chr(i) < chr(i + 1) (chr(i) == chr(i + 1) && tget(i + 1) == 1))? 1 : 0); // s1 int *bkt = (int *)malloc(sizeof(int)*(k + 1)); if (*bkt == NULL){ printf(" (%d)\n", LINE ); return; getbuckets(s, bkt, n, K, cs, true); for (i = 0; i < n; i++){ SA[i] = -1; SA[--bkt[chr(n - 1)]] = n - 1; for (i = 1; i < n - 2; i++){ if (islms(i)) SA[--bkt[chr(i) + 1]] = i; inducesal(t, SA, s, bkt, n, K, cs, false); inducesas(t, SA, s, bkt, n, K, cs, true); free(bkt); // Type-S* SAC n1 int n1 = 0; for (i = 0; i < n; i++){ if (islms(sa[i])) SAC[n1++] = SA[i]; for (i = n1; i < n; i++){ SAC[i] = -1; // SAC[n-1-n1] SAC[n-1] s1 int name = 0, prev = -1; for (i = 0; i < n1; i++) { int pos = SAC[i]; bool diff = false; for (int d = 0; d<n; d++){ if (prev == -1 chr(pos + d)!= chr(prev + d) tget(pos + d)!= tget(prev + d)){ diff = true; break; else if (d>0 && (islms(pos + d) islms(prev + d))){ break; if (diff) { name++; prev = pos; pos = (pos % 2 == 0)? pos / 2 : (pos - 1) / 2; SAC[n1 + pos] = name - 1; for (i = n - 1, j = n - 1; i >= n1; i--){ if (SAC[i] >= 0){ SAC[j--] = SAC[i]; 25

28 // // SA Type-S* int *SA1 = SA, *s1 = SAC + n - n1, *SAC1 = SAC; if (name < n1){ *depth += 1; SA_IS((unsigned char*)s1, SA1, SAC1, n1, name, sizeof(int), bottom, depth); // s1 s SA bkt = (int *)malloc(sizeof(int)*(k + 1)); if (*bkt == NULL){ printf(" (%d)\n", LINE ); return; // S* if (!*bottom){ getbuckets(s, bkt, n, K, cs, true); for (i = 1, j = 0; i < n; i++){ if (islms(i)) s1[j++] = i; for (i = 0; i < n1; i++){ SA1[i] = s1[sa1[i]]; for (i = n1; i < n; i++){ SA[i] = -1; for (i = n1-1; i >= 0; i--) { j = SA[i]; SA[i] = -1; if (i == 0){ SA[--bkt[chr(j)]] = j; else{ SA[--bkt[chr(j) + 1]] = j; inducesal(t, SA, s, bkt, n, K, cs, false); // Type-S(S* ) if (!*bottom){ inducesas(t, SA, s, bkt, n, K, cs, true); else{ *bottom = false; free(bkt); free(t); } // ( BW ) int main(int argc,char *argv[]){ int size = atoi(argv[2]); unsigned char* s = (unsigned char*)malloc(size); // SA SAC int* sa = (int*)malloc(sizeof(int)*size * 2); int* sac = sa + size; unsigned char* L = (unsigned char*)malloc(size); if ((s == NULL) (sa == NULL) (L == NULL)){ printf(" (%d)\n", LINE ); return 0; bool btm; int dep; int I = 0; FILE *fp = fopen(argv[1], "rb"); if (fp == NULL){ 26

29 printf("open error\n"); return -1; if (fread(s, sizeof(char), size - 1, fp) < size - 1){ printf("size error\n"); return -1; fclose(fp); s[size - 1] = \0 ; // Induced Sorting s btm = true; dep = 1; SA_IS(s, sa, sac, size, 256, sizeof(char), &btm, &dep); // s BW L I int i; for (i = 0; i < size; i++){ if (sa[i] == 0){ L[i] = s[size - 1]; I = i; else{ L[i] = s[sa[i] - 1]; /* printf("\n SA =\n"); for (i = 0; i < size; i++){ printf("%d ", SA[i]); printf("\n"); printf("\n L =\n"); for (i = 0; i < size; i++){ printf("%02x ", L[i]); printf("\n"); */ /* FILE *fp1 = fopen("outsa2.txt", "wb"); if (fp1 == NULL){ printf("open error\n"); return -1; fwrite(sa, sizeof(char), size, fp1); fclose(fp1); */ FILE *fp2 = fopen("outl.txt", "wb"); if (fp2 == NULL){ printf("open error\n"); return -1; fwrite(l, sizeof(char), size, fp2); fclose(fp2); FILE *fp3 = fopen("outi.txt", "wt"); if (fp3 == NULL){ printf("open error\n"); return -1; fprintf(fp3, "%d", I); fclose(fp3); free(s); free(sa); free(l); return 0; } 27

スライド 1

スライド 1 参考論文 :Nong, Zhang, and Chan. Two Efficient Algorithms for Linear Suffix Array Construction. (009) Appendix のプログラムの解説 プログラムを Microsoft Visual C++ の環境で動かす際の注意点 先頭で使いそうなライブラリを指定 #include #include

More information

新・明解C言語 ポインタ完全攻略

新・明解C言語 ポインタ完全攻略 2 1-1 1-1 /* 1-1 */ 1 int n = 100; int *p = &n; printf(" n %d\n", n); /* n int */ printf("*&n %d\n", *&n); /* *&n int */ printf(" p %p\n", p); /* p int * */ printf("&*p %p\n", &*p); /* &*p int * */ printf("sizeof(n)

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

ohp03.dvi

ohp03.dvi 19 3 ( ) 2019.4.20 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void int main(int argc, char *argv[]) {... 2 (2) argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0

More information

新・明解C言語 実践編

新・明解C言語 実践編 第 1 章 見 21 1-1 見えないエラー 見 List 1-1 "max2x1.h" a, b max2 List 1-1 chap01/max2x1.h max2 "max2x1.h" #define max2(a, b) ((a) > (b)? (a) : (b)) max2 List 1-2 List 1-2 chap01/max2x1test.c max2 #include

More information

新版明解C言語 実践編

新版明解C言語 実践編 2 List - "max.h" a, b max List - max "max.h" #define max(a, b) ((a) > (b)? (a) : (b)) max List -2 List -2 max #include "max.h" int x, y; printf("x"); printf("y"); scanf("%d", &x); scanf("%d", &y); printf("max(x,

More information

r08.dvi

r08.dvi 19 8 ( ) 019.4.0 1 1.1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( ) 1 next 1 prev 1 head cur tail head cur prev

More information

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D II 8 2003 11 12 1 6 ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 Daisuke 8 =>. 73 Daisuke 35 Hiroshi 64 Ichiro 87 Junko

More information

ohp08.dvi

ohp08.dvi 19 8 ( ) 2019.4.20 1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: 2 (2) NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( 2) 3 (3) head cur tail head cur prev data

More information

r03.dvi

r03.dvi 19 ( ) 019.4.0 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void... argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0 a a \0 b b b \0 c c c \0 1: // argdemo1.c ---

More information

C言語によるアルゴリズムとデータ構造

C言語によるアルゴリズムとデータ構造 Algorithms and Data Structures in C 4 algorithm List - /* */ #include List - int main(void) { int a, b, c; int max; /* */ Ÿ 3Ÿ 2Ÿ 3 printf(""); printf(""); printf(""); scanf("%d", &a); scanf("%d",

More information

memo

memo 数理情報工学演習第一 C ( 第 12 回 ) 2016/07/11 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 今日の内容 : ファイルの入出力 コマンドライン引数 2 分探索 クイックソート ( ライブラリ ) 文字列検索 2 ファイル操作の手続き : ファイル操作 ファイルからのデータ読み込み ファイルへのデータ書き出し 基本的な手順 読みこむ / 書き出すファイルを開く

More information

ex14.dvi

ex14.dvi 1,, 0, b (b b 2 b ) n k n = n j b j, (0 n j b 1), n =(n k n k 1...n 1 n 0 ) b, n j j j +1, 0,...,b 1 (digit). b b, n b 1 ñ, ñ = k (b 1 n j )b j b N, n b n, n = b N n, n =ñ+1 b N, n m n + m (mod b N ),

More information

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó  ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡ (2018) 2018 5 17 0 0 if switch if if ( ) if ( 0) if ( ) if ( 0) if ( ) (0) if ( 0) if ( ) (0) ( ) ; if else if ( ) 1 else 2 if else ( 0) 1 if ( ) 1 else 2 if else ( 0) 1 if ( ) 1 else 2 (0) 2 if else

More information

memo

memo 数理情報工学演習第一 C ( 第 12 回 ) 2017/07/11 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 今日の内容 : ファイルの入出力 コマンドライン引数 2 分探索 最長単調増加列 2 ファイル操作の手続き : ファイル操作 ファイルからのデータ読み込み ファイルへのデータ書き出し 基本的な手順 読みこむ / 書き出すファイルを開く (fopen)

More information

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2  2 B R b I 4 003 4 30 1 ASCII ( ) 0 17 0 NUL 16 DLE SP 0 @ P 3 48 64 80 96 11 p 1 SOH 17 DC1! 1 A Q a 33 49 65 81 97 113 q STX 18 DC " B R b 34 50 66 8 98 114 r 3 ETX 19 DC3 # 3 C S c 35 51 67 83 99 115 s 4 EOT

More information

tuat1.dvi

tuat1.dvi ( 1 ) http://ist.ksc.kwansei.ac.jp/ tutimura/ 2012 6 23 ( 1 ) 1 / 58 C ( 1 ) 2 / 58 2008 9 2002 2005 T E X ptetex3, ptexlive pt E X UTF-8 xdvi-jp 3 ( 1 ) 3 / 58 ( 1 ) 4 / 58 C,... ( 1 ) 5 / 58 6/23( )

More information

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology I117 8 1 School of Information Science, Japan Advanced Institute of Science and Technology : CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and

More information

1 4 2 EP) (EP) (EP)

1 4 2 EP) (EP) (EP) 2003 2004 2 27 1 1 4 2 EP) 5 3 6 3.1.............................. 6 3.2.............................. 6 3.3 (EP)............... 7 4 8 4.1 (EP).................... 8 4.1.1.................... 18 5 (EP)

More information

2008 ( 13 ) C LAPACK 2008 ( 13 )C LAPACK p. 1

2008 ( 13 ) C LAPACK 2008 ( 13 )C LAPACK p. 1 2008 ( 13 ) C LAPACK LAPACK p. 1 Q & A Euler http://phase.hpcc.jp/phase/mppack/long.pdf KNOPPIX MT (Mersenne Twister) SFMT., ( ) ( ) ( ) ( ). LAPACK p. 2 C C, main Asir ( Asir ) ( ) (,,...), LAPACK p.

More information

Microsoft Word - Cプログラミング演習(10)

Microsoft Word - Cプログラミング演習(10) 第 10 回 (6/25) 3. ファイルとその応用 (3) ファイルの更新 シーケンシャルファイルの更新 シーケンシャルファイルでは, 各レコードが可変長で連続して格納されており, その中の特定のレコードを変更することができない そこで一般的には, マスタファイルからデータを取り出し, 更新処理を行ったあとに新マスタファイルに書き込む 注 ) マスタファイル : 主ファイル, 基本ファイルと呼ばれるファイルで内容は比較的固定的であり,

More information

Microsoft Word - Cプログラミング演習(12)

Microsoft Word - Cプログラミング演習(12) 第 12 回 (7/9) 4. いくつかのトピック (5)main 関数の引数を利用したファイル処理 main 関数は, 起動する環境から引数を受け取ることができる 例えば 次に示すように,main 関数に引数を用いたプログラムを作成する 01 /* sample */ 02 /* main 関数の引数 */ 03 #include 04 05 main(int argc, char

More information

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf(hello World\n); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o 18 C ( ) 1 1 1.1 hello world.c 5 printf("hello World\n"); 6 } [ ] [ ] #include % cc hello_world.c %./a.out Hello World [a.out ] % cc hello_world.c -o hello_world [ ( ) ] (K&R 4.1.1) #include

More information

file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose

filea fileb fp = fopen(a, r); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen(b, r); while(fgets(line, BUFSIZ, fp)) {... fclose I117 9 2 School of Information Science, Japan Advanced Institute of Science and Technology file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line,

More information

44 6 MPI 4 : #LIB=-lmpich -lm 5 : LIB=-lmpi -lm 7 : mpi1: mpi1.c 8 : $(CC) -o mpi1 mpi1.c $(LIB) 9 : 10 : clean: 11 : -$(DEL) mpi1 make mpi1 1 % mpiru

44 6 MPI 4 : #LIB=-lmpich -lm 5 : LIB=-lmpi -lm 7 : mpi1: mpi1.c 8 : $(CC) -o mpi1 mpi1.c $(LIB) 9 : 10 : clean: 11 : -$(DEL) mpi1 make mpi1 1 % mpiru 43 6 MPI MPI(Message Passing Interface) MPI 1CPU/1 PC Cluster MPICH[5] 6.1 MPI MPI MPI 1 : #include 2 : #include 3 : #include 4 : 5 : #include "mpi.h" 7 : int main(int argc,

More information

r11.dvi

r11.dvi 19 11 ( ) 2019.4.20 1 / 1.1 ( n n O(n 2 O(n 2 ) ( 1 d n 1 n logn O(nlogn n ( n logn C 1.2 ( ( merge 2 1 1 3 1 4 5 4 2 3 7 9 7 1 2 3 4 5 7 9 1: 2 ivec merge int *ivec_new(int size) { int *a = (int*)malloc((size+1)

More information

ohp11.dvi

ohp11.dvi 19 11 ( ) 2019.4.20 1 / ( ) n O(n 2 ) O(n 2 ) ( ) 1 d n 1 n logn O(nlogn) n ( n logn C ) 2 ( ) ( merge) 2 1 1 3 1 4 5 4 2 3 7 9 7 1 2 3 4 5 7 9 1: 2 ivec merge 3 ( ) (2) int *ivec_new(int size) { int *a

More information

ex12.dvi

ex12.dvi 1 0. C, char., char, 0,. C, ("),., char str[]="abc" ; str abc.,, str 4. str 3. char str[10]="abc" ;, str 10, str 3., char s[]="abc", t[10] ;, t = s. ASCII, 0x00 0x7F, char., "abc" 3, 1. 1 8 256, 2., 2

More information

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

(search: ) [1] ( ) 2 (linear search) (sequential search) 1 2005 11 14 1 1.1 2 1.2 (search:) [1] () 2 (linear search) (sequential search) 1 2.1 2.1.1 List 2-1(p.37) 1 1 13 n

More information

O(N) ( ) log 2 N

O(N) ( ) log 2 N 2005 11 21 1 1.1 2 O(N) () log 2 N 1.2 2 1 List 3-1 List 3-3 List 3-4? 3 3.1 3.1.1 List 2-1(p.70) 1 1 10 1 3.1.2 List 3-1(p.70-71) 1 1 2 1 2 2 1: 1 3 3.1.3 1 List 3-1(p.70-71) 2 #include stdlib.h

More information

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* ( 2016 2016 07 28 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF : 11011 N N 0 N N 11 1001 N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) 1100100 (2) 1111011 (3) 1110010 (4) 1001011

More information

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C 1 6 9 1 main main 1 NULL NULL 1 15 23 25 48 26 30 32 36 38 43 45 47 50 52 for 2 (a) 2 2 1 Yacc 2 (b) 2 3 yytext tmp2 ("") tmp2->next->word tmp2 yytext tmp2->next->word

More information

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n 2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test

More information

2004 2005 2 2 1G01P038-0 1 2 1.1.............................. 2 1.2......................... 2 1.3......................... 3 2 4 2.1............................ 4 2.2....................... 4 2.3.......................

More information

double float

double float 2015 3 13 1 2 2 3 2.1.......................... 3 2.2............................. 3 3 4 3.1............................... 4 3.2 double float......................... 5 3.3 main.......................

More information

卒 業 研 究 報 告.PDF

卒 業 研 究 報 告.PDF C 13 2 9 1 1-1. 1-2. 2 2-1. 2-2. 2-3. 2-4. 3 3-1. 3-2. 3-3. 3-4. 3-5. 3-5-1. 3-5-2. 3-6. 3-6-1. 3-6-2. 4 5 6 7-1 - 1 1 1-1. 1-2. ++ Lisp Pascal Java Purl HTML Windows - 2-2 2 2-1. 1972 D.M. (Dennis M Ritchie)

More information

C B

C B C 095707B 2010 6 8 1 LEVE1 2 1.1 LEVEL 1.1................................................ 2 1.1.1 1................................................ 2 1.1.2 1.2..............................................

More information

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1 I117 II I117 PROGRAMMING PRACTICE II 2 MEMORY MANAGEMENT 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp / SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming

More information

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * * 2015 2015 07 30 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) +

More information

Prog1_6th

Prog1_6th 2012 年 5 月 24 日 ( 木 ) 実施 多分岐のプログラム 前回は多段階の 2 分岐を組み合わせて 3 種類以上の場合分けを実現したが, 式の値の評価によって, 一度に多種類の場合分けを行う多分岐の利用によって見通しのよいプログラムを作成できる場合がある ( 流れ図は右図 ) 式の評価 : 値 1 : 値 2 : 値 n : 該当値無し 処理 1 処理 2 処理 n 既定の処理 switch

More information

1.3 ( ) ( ) C

1.3 ( ) ( ) C 1 1.1 (Data Base) (Container) C++ Java 1.2 1 1.3 ( ) ( ) 1. 2. 3. C++ 2 2.1 2.2 2.3 2 C Fortran C++ Java 3 3.1 (Vector) 1. 2. ( ) 3.2 3 3.3 C++ C++ STL C++ (Template) vector vector< > ; int arrayint vector

More information

program.dvi

program.dvi 2001.06.19 1 programming semi ver.1.0 2001.06.19 1 GA SA 2 A 2.1 valuename = value value name = valuename # ; Fig. 1 #-----GA parameter popsize = 200 mutation rate = 0.01 crossover rate = 1.0 generation

More information

lexex.dvi

lexex.dvi (2018, c ) http://istksckwanseiacjp/ ishiura/cpl/ 4 41 1 mini-c lexc,, 2 testlexc, lexc mini-c 1 ( ) mini-c ( ) (int, char, if, else, while, return 6 ) ( ) (+, -, *, /, %, &, =, ==,!=, >, >=,

More information

:30 12:00 I. I VI II. III. IV. a d V. VI

:30 12:00 I. I VI II. III. IV. a d V. VI 2017 2017 08 03 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF X [ S ] a S S ; X X X, S [, a, ], ; BNF X (parse tree) (1) [a;a] (2) [[a]] (3) [a;[a]] (4) [[a];a] : [a] X 2 222222

More information

:30 12:00 I. I VI II. III. IV. a d V. VI

:30 12:00 I. I VI II. III. IV. a d V. VI 2018 2018 08 02 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF N N y N x N xy yx : yxxyxy N N x, y N (parse tree) (1) yxyyx (2) xyxyxy (3) yxxyxyy (4) yxxxyxxy N y N x N yx

More information

untitled

untitled II 4 Yacc Lex 2005 : 0 1 Yacc 20 Lex 1 20 traverse 1 %% 2 [0-9]+ { yylval.val = atoi((char*)yytext); return NUM; 3 "+" { return + ; 4 "*" { return * ; 5 "-" { return - ; 6 "/" { return / ; 7 [ \t] { /*

More information

C

C C 1 2 1.1........................... 2 1.2........................ 2 1.3 make................................................ 3 1.4....................................... 5 1.4.1 strip................................................

More information

実際の株価データを用いたオプション料の計算

実際の株価データを用いたオプション料の計算 2002 2 20 1 1 3 2 3 2.1 : : : : : : : : : : : : : : : : : : : : : : : : : : : : 5 2.1.1 : : : : : : : : : : : : : : : : : : : : 5 2.1.2 : : : : : : : : : : : : : : : : : : : : 6 2.2 : : : : : : : : : :

More information

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0)

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0) E-mail: takio-kurita@aist.go.jp 1 ( ) CPU ( ) 2 1. a f(a) =(a 1.0) 2 (1) a ( ) 1(a) f(a) a (1) a f(a) a =2(a 1.0) (2) 2 0 a f(a) a =2(a 1.0) = 0 (3) 1 9 8 7 (x-1.0)*(x-1.0) 6 4 2.0*(x-1.0) 6 2 5 4 0 3-2

More information

untitled

untitled Q 8 1 8.1 (C++) C++ cin cout 5 C++ 16 6 p.63 8.3 #include 7 showbase noshowbase showpoint noshowpoint 8.3 uppercase 16 nouppercase 16 setfill(int) setprecision(int) setw(int) setbase(int) dec

More information

超初心者用

超初心者用 3 1999 10 13 1. 2. hello.c printf( Hello, world! n ); cc hello.c a.out./a.out Hello, world printf( Hello, world! n ); 2 Hello, world printf n printf 3. ( ) int num; num = 100; num 100 100 num int num num

More information

joho07-1.ppt

joho07-1.ppt 0xbffffc5c 0xbffffc60 xxxxxxxx xxxxxxxx 00001010 00000000 00000000 00000000 01100011 00000000 00000000 00000000 xxxxxxxx x y 2 func1 func2 double func1(double y) { y = y + 5.0; return y; } double func2(double*

More information

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1: 005 9 7 1 1.1 1 Hello World!! 5 p r i n t f ( H e l l o World!! \ n ) ; 7 return 0 ; 8 } 1: 1 [ ] Hello World!! from Akita National College of Technology. 1 : 5 p r i n t f ( H e l l o World!! \ n ) ;

More information

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B A/B (2018/10/19) Ver. 1.0 kurino@math.cst.nihon-u.ac.jp http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2018/soft/soft.html 2018 10 19 A/B 1 2018 10 19 2 1 1 1.1 OHP.................................... 1

More information

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó  ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡ (2018) 2018 5 24 ( ) while ( ) do while ( ); for ( ; ; ) while int i = 0; while (i < 100) { printf("i = %3d\n", i); i++; while int i = 0; i while (i < 100) { printf("i = %3d\n", i); i++; while int i =

More information

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in C 1 / 21 C 2005 A * 1 2 1.1......................................... 2 1.2 *.......................................... 3 2 4 2.1.............................................. 4 2.2..............................................

More information

I J

I J I 065763J 8 7 7 31 jikken/ +----- accumulation_demupa.c +----- accumulation_rain.c +----- frequency_demupa.c +----- frequency_rain.c +----- go.sh +----- graph_maker.sh +----- mesure-ryudai/ 2007/4/1 2007/6/30

More information

comment.dvi

comment.dvi ( ) (sample1.c) (sample1.c) 2 2 Nearest Neighbor 1 (2D-class1.dat) 2 (2D-class2.dat) (2D-test.dat) 3 Nearest Neighbor Nearest Neighbor ( 1) 2 1: NN 1 (sample1.c) /* -----------------------------------------------------------------

More information

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >= II 14 2018 7 26 : : proen@mm.ics.saitama-u.ac.jp 14,, 8 2 12:00 1 O(1) n O(n) O(log n) O(1) 32 : 1G int 4 250 M 2.5 int 21 2 0 100 0 100 #include #define HASHSIZE 100 /* */ #define NOTFOUND 0

More information

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E 8 9 7 6 4 2 3 5 1 j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E a n 1 H = ae l j, j=1 l j = x j+1 x j, x n x 1 = n 1 j=1 l j, l j = ±l l > 0) n 1 H = ϵ l j, j=1 ϵ e x x

More information

DVIOUT

DVIOUT 2009 年度情報科学 & 情報科学演習レポート 9 学生用 学籍番号 : 氏名 : 下記の注意事項を守り 次ページ以降の問いに答え レポートを完成させなさい 提出期限 : 2009 年 6 月 30 日 ( 火 ) 13:00 まで提出場所 : 理学部棟正面玄関内に設置のレポートボックス 注意事項 : (1) このページを印刷し 必要事項を記入の上 ( 学籍番号欄と氏名欄は 2 箇所あるので忘れずに記入すること

More information

Condition DAQ condition condition 2 3 XML key value

Condition DAQ condition condition 2 3 XML key value Condition DAQ condition 2009 6 10 2009 7 2 2009 7 3 2010 8 3 1 2 2 condition 2 3 XML key value 3 4 4 4.1............................. 5 4.2...................... 5 5 6 6 Makefile 7 7 9 7.1 Condition.h.............................

More information

橡Pro PDF

橡Pro PDF 1 void main( ) char c; /* int c; */ int sum=0; while ((c = getchar())!= EOF) if(isdigit(c) ) sum += (c-'0'); printf("%d\n", sum); main()int i,sum=0; for(i=0;i

More information

Taro-リストⅠ(公開版).jtd

Taro-リストⅠ(公開版).jtd 0. 目次 1. 再帰的なデータ構造によるリストの表現 1. 1 リストの作成と表示 1. 1. 1 リストの先頭に追加する方法 1. 1. 2 リストの末尾に追加する方法 1. 1. 3 昇順を保存してリストに追加する方法 1. 2 問題 問題 1 問題 2-1 - 1. 再帰的なデータ構造によるリストの表現 リストは データの一部に次のデータの記憶場所を示す情報 ( ポインタという ) を持つ構造をいう

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション プログラミング応用演習 第 5 回演習 前回までのお話 ポインタ ポインタを用いた文字列処理 構造体 ファイル 再帰的構造体 リスト構造 動的メモリ管理 今日のお題 ポインタやファイルなど これまでの内容の練習 教材 以前 以下に単語を収録したファイルがあることを紹介した : /usr/share/dict/words この中からランダムに単語を取り出したファイルを用意した http://sun.ac.jp/prof/yamagu/2019app/

More information

‚æ4›ñ

‚æ4›ñ ( ) ( ) ( ) 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 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 (OUS) 9 26 1 / 28 ( ) ( ) ( ) A B C D Z a b c d z 0 1 2 9 (OUS) 9

More information

目 目 用方 用 用 方

目 目 用方 用 用 方 大 生 大 工 目 目 用方 用 用 方 用 方 MS-MPI MPI.NET MPICH MPICH2 LAM/MPI Ver. 2 2 1 2 1 C C++ Fortan.NET C# C C++ Fortan 用 行 用 用 用 行 用 言 言 言 行 生 方 方 一 行 高 行 行 文 用 行 If ( rank == 0 ) { // 0 } else if (rank == 1) {

More information

programmingII2019-v01

programmingII2019-v01 II 2019 2Q A 6/11 6/18 6/25 7/2 7/9 7/16 7/23 B 6/12 6/19 6/24 7/3 7/10 7/17 7/24 x = 0 dv(t) dt = g Z t2 t 1 dv(t) dt dt = Z t2 t 1 gdt g v(t 2 ) = v(t 1 ) + g(t 2 t 1 ) v v(t) x g(t 2 t 1 ) t 1 t 2

More information

1.ppt

1.ppt /* * Program name: hello.c */ #include int main() { printf( hello, world\n ); return 0; /* * Program name: Hello.java */ import java.io.*; class Hello { public static void main(string[] arg)

More information

XMPによる並列化実装2

XMPによる並列化実装2 2 3 C Fortran Exercise 1 Exercise 2 Serial init.c init.f90 XMP xmp_init.c xmp_init.f90 Serial laplace.c laplace.f90 XMP xmp_laplace.c xmp_laplace.f90 #include int a[10]; program init integer

More information

ex01.dvi

ex01.dvi ,. 0. 0.0. C () /******************************* * $Id: ex_0_0.c,v.2 2006-04-0 3:37:00+09 naito Exp $ * * 0. 0.0 *******************************/ #include int main(int argc, char **argv) double

More information

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² – (2018) 11 2018 12 13 2 g v dv x dt = bv x, dv y dt = g bv y (1) b v 0 θ x(t) = v 0 cos θ ( 1 e bt) (2) b y(t) = 1 ( v 0 sin θ + g ) ( 1 e bt) g b b b t (3) 11 ( ) p14 2 1 y 4 t m y > 0 y < 0 t m1 h = 0001

More information

para02-2.dvi

para02-2.dvi 2002 2 2002 4 23 : MPI MPI 1 MPI MPI(Message Passing Interface) MPI UNIX Windows Machintosh OS, MPI 2 1 1 2 2.1 1 1 1 1 1 1 Fig. 1 A B C F Fig. 2 A B F Fig. 1 1 1 Fig. 2 2.2 Fig. 3 1 . Fig. 4 Fig. 3 Fig.

More information

Taro-ファイル処理(公開版).jtd

Taro-ファイル処理(公開版).jtd ファイル処理 0. 目次 1. はじめに 2. ファイル内容の表示 3. ファイル内容の複写 3. 1 文字単位 3. 2 行単位 4. 書式付き入出力 5. 文字配列への入出力 6. 課題 6. 1 課題 1 ( ファイル圧縮 復元 ) - 1 - 1. はじめに ファイル処理プログラムの形は次のようになる #include main() { FILE *fp1,*fp2; ファイルポインタの宣言

More information

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l C/C++ 2007 6 18 1 C STL(1) 2 1.1............................................... 2 1.2 stdio................................................ 3 1.3.......................................... 10 2 11 2.1 sizeof......................................

More information

kiso2-09.key

kiso2-09.key 座席指定はありません 計算機基礎実習II 2018 のウェブページか 第9回 ら 以下の課題に自力で取り組んで下さい 計算機基礎実習II 第7回の復習課題(rev07) 第9回の基本課題(base09) 第8回試験の結果 中間試験に関するコメント コンパイルできない不完全なプログラムなど プログラミングに慣れていない あるいは複雑な問題は 要件 をバラして段階的にプログラムを作成する exam08-2.c

More information

Krylov (b) x k+1 := x k + α k p k (c) r k+1 := r k α k Ap k ( := b Ax k+1 ) (d) β k := r k r k 2 2 (e) : r k 2 / r 0 2 < ε R (f) p k+1 :=

Krylov (b) x k+1 := x k + α k p k (c) r k+1 := r k α k Ap k ( := b Ax k+1 ) (d) β k := r k r k 2 2 (e) : r k 2 / r 0 2 < ε R (f) p k+1 := 127 10 Krylov Krylov (Conjugate-Gradient (CG ), Krylov ) MPIBNCpack 10.1 CG (Conjugate-Gradient CG ) A R n n a 11 a 12 a 1n a 21 a 22 a 2n A T = =... a n1 a n2 a nn n a 11 a 21 a n1 a 12 a 22 a n2 = A...

More information

PowerPoint Presentation

PowerPoint Presentation p.130 p.198 p.208 2 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i i < NUM; i++ ) ) if if ( weight[i] > max ) max = weight[i]: if if ( weight[i] < min ) min = weight[i]: weight

More information

<4D F736F F D208B5A8F708FEE95F F090CD894A97CA81458D7E925A B B835E92F18B9F816A2E646F63>

<4D F736F F D208B5A8F708FEE95F F090CD894A97CA81458D7E925A B B835E92F18B9F816A2E646F63> 平成 年 月 日気象庁予報部 配信資料に関する技術情報 ( 気象編 ) 第 号 ~FTP 方式の 0 分毎の解析雨量及び降水短時間予報 GPV のサンプルデータの提供について ~ 配信資料に関する技術情報 ( 気象編 ) 第 号において 毎正時及び正時 +0 分を初期時刻とする解析雨量及び降水短時間予報について 全国分のデータをファイルとしてFTP 方式での提供を開始すること及びそのフォーマットについてお知らせしました

More information

情報処理演習 B8クラス

情報処理演習 B8クラス 予定スケジュール ( 全 15 回 ) 1 1. 終了 プログラミング言語の基礎 2. 終了 演算と型 3. 終了 プログラムの流れの分岐 (if 文,switch 文など ) 4. 終了 プログラムの流れの繰返し (do, while, for 文など ) 5. 終了 中間レポート1 6. 終了 配列 7. 終了 関数 8. 終了 文字列 ( 文字列の配列, 文字列の操作 ) 9. 終了 ポインタ

More information

& & a a * * ptr p int a ; int *a ; int a ; int a int *a

& & a a * * ptr p int a ; int *a ; int a ; int a int *a int a = 123; a 123 :100 a 123 int *ptr = & a; a ptr ptr a 100 a 123 200 *ptr 200 a & & a a * * ptr p --------------------------------------------------------------------------------------------- int a

More information

DKA ( 1) 1 n i=1 α i c n 1 = 0 ( 1) 2 n i 1 <i 2 α i1 α i2 c n 2 = 0 ( 1) 3 n i 1 <i 2 <i 3 α i1 α i2 α i3 c n 3 = 0. ( 1) n 1 n i 1 <i 2 < <i

DKA ( 1) 1 n i=1 α i c n 1 = 0 ( 1) 2 n i 1 <i 2 α i1 α i2 c n 2 = 0 ( 1) 3 n i 1 <i 2 <i 3 α i1 α i2 α i3 c n 3 = 0. ( 1) n 1 n i 1 <i 2 < <i 149 11 DKA IEEE754 11.1 DKA n p(x) = a n x n + a n 1 x n 1 + + a 0 (11.1) p(x) = 0 (11.2) p n (x) q n (x) = x n + c n 1 x n 1 + + c 1 x + c 0 q n (x) = 0 (11.3) c i = a i a n (i = 0, 1,..., n 1) (11.3)

More information

Taro-2分探索木Ⅱ(公開版).jtd

Taro-2分探索木Ⅱ(公開版).jtd 2 分探索木 Ⅱ 0. 目次 5. 2 分探索木の操作 5. 1 要素の探索 5. 2 直前の要素の探索 5. 3 直後の要素の探索 5. 4 要素の削除 5. 5 問題 問題 1-1 - 5. 2 分探索木の操作 5. 1 要素の探索 要素 44 の探索 (1) 要素 と 44 を比較して 左部分木をたどる (2) 要素 33 と 44 を比較して 右部分木をたどる (3) 要素 44 を見つけた

More information

Taro-再帰関数Ⅱ(公開版).jtd

Taro-再帰関数Ⅱ(公開版).jtd 0. 目次 6. 2 項係数 7. 二分探索 8. 最大値探索 9. 集合 {1,2,,n} 上の部分集合生成 - 1 - 6. 2 項係数 再帰的定義 2 項係数 c(n,r) は つぎのように 定義される c(n,r) = c(n-1,r) + c(n-1,r-1) (n 2,1 r n-1) = 1 (n 0, r=0 ) = 1 (n 1, r=n ) c(n,r) 0 1 2 3 4 5

More information

新・明解C言語で学ぶアルゴリズムとデータ構造

新・明解C言語で学ぶアルゴリズムとデータ構造 第 1 章 基本的 1 n 141 1-1 三値 最大値 algorithm List 1-1 a, b, c max /* */ #include int main(void) { int a, b, c; int max; /* */ List 1-1 printf("\n"); printf("a"); scanf("%d", &a); printf("b"); scanf("%d",

More information

DA100データアクイジションユニット通信インタフェースユーザーズマニュアル

DA100データアクイジションユニット通信インタフェースユーザーズマニュアル Instruction Manual Disk No. RE01 6th Edition: November 1999 (YK) All Rights Reserved, Copyright 1996 Yokogawa Electric Corporation 801234567 9 ABCDEF 1 2 3 4 1 2 3 4 1 2 3 4 1 2

More information

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

[1] #include<stdio.h> main() { printf(hello, world.); return 0; } (G1) int long int float ± ± [1] #include printf("hello, world."); (G1) int -32768 32767 long int -2147483648 2147483647 float ±3.4 10 38 ±3.4 10 38 double ±1.7 10 308 ±1.7 10 308 char [2] #include int a, b, c, d,

More information

AutoTuned-RB

AutoTuned-RB ABCLib Working Notes No.10 AutoTuned-RB Version 1.00 AutoTuned-RB AutoTuned-RB RB_DGEMM RB_DGEMM ( TransA, TransB, M, N, K, a, A, lda, B, ldb, b, C, ldc ) L3BLAS DGEMM (C a Trans(A) Trans(B) b C) (1) TransA:

More information

pptx

pptx iphone 2010 8 18 C xkozima@myu.ac.jp C Hello, World! Hello World hello.c! printf( Hello, World!\n );! os> ls! hello.c! os> cc hello.c o hello! os> ls! hello!!hello.c! os>./hello! Hello, World!! os>! os>

More information

演算増幅器

演算増幅器 ネットワークプログラミングの続き前回はチャットを行うプログラムを作成し ネットワークを利用したプログラミングの基本について学んだ 本日は 前回作成したプログラムを改良していく 具体的には 以下の2つの項目について習っていく ホスト名や IP アドレスの取得の方法 fork() システムコールを使い 子プロセスを作成する方法 チャットプログラムの改良 前回のプログラムを以下のように改良していく 太字部分が変更部分である

More information

スライド タイトルなし

スライド タイトルなし ファイル入出力 (2) これまでのおさらい ( 入出力 ) これまでの入出力は 入力 scanf 出力 printf キーボードと画面 ( 端末 ) scanf/printf は 書式つき入出力 フォーマットを指定する 標準入出力を対象とする 何もしなければ 標準入出力は キーボードと画面 ストリームという考え方 ストリーム (stream) = データの列 キーボードから打つ文字列 画面に出力される文字列

More information

Taro-リストⅢ(公開版).jtd

Taro-リストⅢ(公開版).jtd リスト Ⅲ 0. 目次 2. 基本的な操作 2. 1 リストから要素の削除 2. 2 リストの複写 2. 3 リストの連結 2. 4 問題 問題 1 問題 2-1 - 2. 基本的な操作 2. 1 リストから要素の削除 まず 一般的な処理を書き つぎに 特別な処理を書く 一般的な処理は 処理 1 : リスト中に 削除するデータを見つけ 削除する場合への対応 特別な処理は 処理 2 : 先頭のデータを削除する場合への対応

More information

1 ( ) 1.1 (convert.sh) (18GHz 26GHz) C (convert.c, convert1.c) mesure-ryudai convert.sh #!/bin/sh # file1 file1= ls -1 $1 # file1 data for data in $fi

1 ( ) 1.1 (convert.sh) (18GHz 26GHz) C (convert.c, convert1.c) mesure-ryudai convert.sh #!/bin/sh # file1 file1= ls -1 $1 # file1 data for data in $fi I 065712D : 4 1 ( ) 1.1 (convert.sh) (18GHz 26GHz) C (convert.c, convert1.c) mesure-ryudai convert.sh #!/bin/sh # file1 file1= ls -1 $1 # file1 data for data in $file1 do mkdir $data echo " $data " # file2

More information

QR

QR 1 7 16 13 1 13.1 QR...................................... 2 13.1.1............................................ 2 13.1.2..................................... 3 13.1.3 QR........................................

More information

Microsoft Word - C.....u.K...doc

Microsoft Word - C.....u.K...doc C uwêííôöðöõ Ð C ÔÖÐÖÕ ÐÊÉÌÊ C ÔÖÐÖÕÊ C ÔÖÐÖÕÊ Ç Ê Æ ~ if eíè ~ for ÒÑÒ ÌÆÊÉÉÊ ~ switch ÉeÍÈ ~ while ÒÑÒ ÊÍÍÔÖÐÖÕÊ ~ 1 C ÔÖÐÖÕ ÐÊÉÌÊ uê~ ÏÒÏÑ Ð ÓÏÖ CUI Ô ÑÊ ÏÒÏÑ ÔÖÐÖÕÎ d ÈÍÉÇÊ ÆÒ Ö ÒÐÑÒ ÊÔÎÏÖÎ d ÉÇÍÊ

More information

char char 1 signed char unsigned char ( ; single-quote 0x27) ASCII Japan Advanced Institute of Science and Technology

char char 1 signed char unsigned char ( ; single-quote 0x27) ASCII Japan Advanced Institute of Science and Technology I117 3 1 School of Information Science, Japan Advanced Institute of Science and Technology char char 1 signed char -128 127 unsigned char 0 255 ( ; single-quote 0x27) ASCII Japan Advanced Institute of

More information

A/B (2010/10/08) Ver kurino/2010/soft/soft.html A/B

A/B (2010/10/08) Ver kurino/2010/soft/soft.html A/B A/B (2010/10/08) Ver. 1.0 kurino@math.cst.nihon-u.ac.jp http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2010/soft/soft.html 2010 10 8 A/B 1 2010 10 8 2 1 1 1.1 OHP.................................... 1 1.2.......................................

More information

Prog1_15th

Prog1_15th 2012 年 7 月 26 日 ( 木 ) 実施構造体と typedef typedef 宣言によって,struct 構造体タグ名という表記を再定義し, データ型名のように扱うことができる 構文は typedef struct 構造体タグ名 再定義名 ; となり, この場合の構造体変数の宣言は, 再定義名を用いて行うことができる なお, ここでは 構造体タグ名は省略可能である 構造体を指すポインタ

More information