close

最開始是``再來是'' 互相交換

網址:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=208

--------------------------------------------------------------------

#include <stdio.h>

int main()
{
    int flag = 0;
    char ch;

    while( (ch = getchar() ) != EOF )
        if(ch == '"')
        {
            printf("%s", flag ? "''" : "``");
            flag = !flag;
        }
        else
            printf("%c", ch);

    return 0;
}
 

 

-2015-05-22-----------------------------------------------------------------

package test;

import java.util.*;

public class main {

    public static void main(String[] args) {
        try {
            final Scanner in = new Scanner(System.in);
            boolean flag = true;

            while (in.hasNextLine()) {
                String str = in.nextLine();
                for (int i = 0; i < str.length(); i++) {
                    char ch = str.charAt(i);
                    if (ch == '\"') {
                        if (true == flag) {
                            System.out.print("``");
                            flag = false;
                        } else {
                            System.out.print("''");
                            flag = true;
                        }
                    } else {
                        System.out.print("" + ch);
                    }
                }
                System.out.println("");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 

arrow
arrow
    全站熱搜

    awesq123 發表在 痞客邦 留言(0) 人氣()