ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Solving USACO Name That Number problem in c++
    ALGORITHM/USACO 2019. 8. 11. 23:07
    728x90

    It is always afraid me to recieve file input 

    but it is nothing difficult

    #include<fstream>
    #include <string>
    using namespace std;
    string memo[13];
    int main() {
    
    	string N;
    	ifstream openfile("dict.txt");
    	ofstream fout("namenum.out");
    	ifstream fin("namenum.in");
    	bool check = true;
    	fin >> N;
    	if (openfile.is_open()) {
    		string line;
    		while (getline(openfile, line)) {
    		string answer;
    			for (int i = 0; i < line.size(); i++) {
    				if (line[i] == 'A' || line[i] == 'B' || line[i] == 'C') {
    					answer += "2";
    				}
    				else if (line[i] == 'D' || line[i] == 'E' || line[i] == 'F') {
    					answer += "3";
    				}
    				else if (line[i] == 'G' || line[i] == 'H' || line[i] == 'I') {
    					answer += "4";
    				}
    				else if (line[i] == 'J' || line[i] == 'K' || line[i] == 'L') {
    					answer += "5";
    				}
    				else if (line[i] == 'M' || line[i] == 'N' || line[i] == 'O') {
    					answer += "6";
    				}
    				else if (line[i] == 'P' || line[i] == 'R' || line[i] == 'S') {
    					answer += "7";
    				}
    				else if (line[i] == 'T' || line[i] == 'U' || line[i] == 'V') {
    					answer += "8";
    				}
    				else if (line[i] == 'W' || line[i] == 'X' || line[i] == 'Y') {
    					answer += "9";
    				}
    			}
    			if (answer == N) {
    				fout << line<<endl;
    				check = false;
    			}
    		}
    	}
    	if(check)
    		fout << "NONE" << endl;
    	return 0;
    }

    'ALGORITHM > USACO' 카테고리의 다른 글

    solving USACO dualpal problem in c++  (0) 2019.08.12
    Solving USACO palsquare problem in c++  (0) 2019.08.12
    Solving the usaco transform problem in c++  (0) 2019.08.11
    Milking Cows /c++  (0) 2019.08.11
    Broken Necklace /c++  (0) 2019.08.11

    댓글

Designed by Tistory.