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> | |
| #define MAXSTRINGS 10000 | |
| // 1-23に同じく、catとパイプでソースを受け取る | |
| int main(){ | |
| int c; | |
| char str[MAXSTRINGS]; | |
| int i = 0, j; | |
| int n = 1; | |
| int qflg =0; // normal -> 0, sq -> 1, dq -> 2 | |
| int eflg = 0; // normal -> 0, // -> 1, /* -> 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> | |
| #define MAXCHARS 1000 | |
| void getlined(char s[], int lim); | |
| int main(){ | |
| char s[MAXCHARS]; | |
| getlined(s, MAXCHARS); | |
| printf("%s\n", s); | |
| } |
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
| [tomcha]$ cat 2-3.c | |
| #include <stdio.h> | |
| int htoi(char s[]); | |
| int main(){ | |
| printf("%d\n", htoi("0x1a\n")); | |
| } | |
| int htoi(char s[]){ | |
| int result = 0; |
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> | |
| void squeeze(char s1[], char s2[]); | |
| int main(){ | |
| char s1[11] = "abcdefffc\n"; | |
| char s2[4] = "ce\n"; | |
| squeeze(s1, s2); | |
| printf("%s\n", s1); | |
| } |
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> | |
| int any(char s1[], char s2[]); | |
| int main(){ | |
| //"abcdefg" | |
| //"cde" -> 2 | |
| //"cdf" -> -1 | |
| printf("1:%d\n", any("abcdef", "cde")); | |
| printf("2:%d\n", any("abcdef", "cdf")); |
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> | |
| int unsigned setbits(unsigned x, int p, int n, unsigned y); | |
| int main(){ | |
| int x = 0b001110; | |
| int y = 0b0000000; | |
| int val = setbits(x, 3, 3, y); | |
| printf("%d\n", val); | |
| // answer 0b0000111 -> 7; |
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> | |
| int invert(unsigned x, int p, int n); | |
| int main(){ | |
| int x = 0b00011100; | |
| int y = 0b00010000; | |
| // x -> 0b00000000 = 0 | |
| // y -> 0b00001100 = 12 |
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> | |
| int rightrot(unsigned x, int n); | |
| int main(){ | |
| int x = 0b111010; | |
| printf("%d\n",rightrot(x, 2)); | |
| // 111010 -> 101110 = 46 | |
| } | |
| int rightrot(unsigned x, int n){ |
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> | |
| int bitcount_kai(unsigned x); | |
| int main(){ | |
| printf("%d\n", bitcount_kai(9)); | |
| } | |
| int bitcount_kai(unsigned x){ | |
| int b = 0; |
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> | |
| int lower(int c); | |
| int main(){ | |
| printf("%c\n", lower('T')); | |
| printf("%c\n", lower('t')); | |
| printf("%c\n", lower('Z')); | |
| printf("%c\n", lower('z')); | |
| } |