Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

인터프리터/권정욱: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0006 pages from live compare)
 
Line 9: Line 9:
   
   
  int main(){
  int main(){
  string num[100];
  string num[100];
  int array = 0;
  int array = 0;
  int temp1 = 0;
  int temp1 = 0;
Line 17: Line 17:
 
 
  for (int i =0; i<100; i++){
  for (int i =0; i<100; i++){
  num[i] = "000";
  num[i] = "000";
  }
  }
  while(!fin.eof()){
  while(!fin.eof()){
  string instruction;
  string instruction;
  fin >> instruction;
  fin >> instruction;
  if (instruction[0] != '*') {
  if (instruction[0] != '*') {
  num[array] = instruction;
  num[array] = instruction;
  array++;
  array++;
  }
  }
Line 31: Line 31:
  array = 0;
  array = 0;
   
   
  while(num[array] != "000"){
  while(num[array] != "000"){
  if (num[array] == "901") {
  if (num[array] == "901") {
  cout << "입력 : ";
  cout << "입력 : ";
  cin >> temp1;
  cin >> temp1;
  }
  }
  else if (num[array] == "902")
  else if (num[array] == "902")
  cout << "출력 : " << temp1;
  cout << "출력 : " << temp1;
  else if (num[array] == "000") break;
  else if (num[array] == "000") break;
  else if (num[array][1] == '1') {
  else if (num[array][1] == '1') {
  temp2 = num[array].substr(1,2).c_str());
  temp2 = num[array].substr(1,2).c_str());
  temp1 += temp2;
  temp1 += temp2;
  }
  }
  else if (num[array][1] == '2') {
  else if (num[array][1] == '2') {
  temp2 = num[array].substr(1,2).c_str());
  temp2 = num[array].substr(1,2).c_str());
  temp1 -= temp2;
  temp1 -= temp2;
  }
  }
  else if (num[array][1] == '3') {
  else if (num[array][1] == '3') {
  temp2 = num[array].substr(1,2).c_str());
  temp2 = num[array].substr(1,2).c_str());
  temp1 += temp2;
  temp1 += temp2;
  }
  }
  else if (num[array][1] == '5') {
  else if (num[array][1] == '5') {
  temp2 = num[array].substr(1,2).c_str());
  temp2 = num[array].substr(1,2).c_str());
  temp1 += temp2;
  temp1 += temp2;
  }
  }
  }
  }
  for (i = 0; i< 100; i++){
  for (i = 0; i< 100; i++){
  cout << instruction[i];
  cout << instruction[i];
  if ((i%10) == 0) cout << endl;
  if ((i%10) == 0) cout << endl;
  }
  }
Line 63: Line 63:
  }
  }


[[가상머신만들기]]
가상머신만들기
 

Latest revision as of 01:08, 27 March 2026

인터프리너/권정욱

미완성

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

int main(){
	string num[100];
	int array = 0;
	int temp1 = 0;
	int temp2 = 0;
	ifstream fin("인터프리터.txt");
	ofstream fout("인터프리터결과.txt");
	
	for (int i =0; i<100; i++){
		num[i] = "000";
	}
	while(!fin.eof()){
		string instruction;
		fin >> instruction;
		if (instruction[0] != '*') {
			num[array] = instruction;
			array++;
		}
		else array = atoi(instruction.substr(1, 2).c_str());
	}

	array = 0;

	while(num[array] != "000"){
		if (num[array] == "901") {
			cout << "입력 : ";
			cin >> temp1;
		}
		else if (num[array] == "902")
			cout << "출력 : " << temp1;
		else if (num[array] == "000") break;
		else if (num[array][1] == '1') {
			temp2 = num[array].substr(1,2).c_str());
			temp1 += temp2;
		}
		else if (num[array][1] == '2') {
			temp2 = num[array].substr(1,2).c_str());
			temp1 -= temp2;
		}
		else if (num[array][1] == '3') {
			temp2 = num[array].substr(1,2).c_str());
			temp1 += temp2;
		}
		else if (num[array][1] == '5') {
			temp2 = num[array].substr(1,2).c_str());
			temp1 += temp2;
		}
	}
	for (i = 0; i< 100; i++){
		cout << instruction[i];
		if ((i%10) == 0) cout << endl;
	}
	return 0;
}

가상머신만들기