Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define CAN_PRINT 0
- #define MET_SLASH 1
- #define MET_LINE_COMM 2
- #define MET_BLOCK_COMM 3
- #define MET_END_BLOCK_STAR 4
- int main() {
- short state = CAN_PRINT;
- for (char ch; (ch = getchar()) != EOF;) {
- if (ch == '/' && state == CAN_PRINT) {
- state = MET_SLASH;
- } else if (ch == '/' && state == MET_SLASH) {
- state = MET_LINE_COMM;
- } else if (ch == '*' && state == MET_SLASH) {
- state = MET_BLOCK_COMM;
- } else if (ch == '\n' && state == MET_LINE_COMM) {
- state = CAN_PRINT;
- } else if (ch == '*' && state == MET_BLOCK_COMM) {
- state = MET_END_BLOCK_STAR;
- } else if (ch == '/' && state == MET_END_BLOCK_STAR) {
- state = CAN_PRINT;
- continue;
- } else if (ch != '/' && state == MET_SLASH) {
- putchar('/');
- state = CAN_PRINT;
- } else if (ch != '/' && state == MET_END_BLOCK_STAR) {
- state = MET_BLOCK_COMM;
- }
- putchar(state == CAN_PRINT ? ch : 0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement