program_3_4.cpp

来自「清华关于C++ 的程序讲义 值得一看 关于算法」· C++ 代码 · 共 28 行

CPP
28
字号
#include <iostream>
#include <string>
using namespace std;

int main()
{
	// Prompt for and read the date
	cout << "Enter the date in American format "
	<< "(e.g., December 29, 1953): ";
    char buffer[100];
	string Date;
	cin.getline(buffer, 100);
	// Get the month by finding the first blank character
	Date = buffer;
	int i = Date.find(" ");
	string Month = Date.substr(0, i);
	// Get the day by finding the comma character
	int k = Date.find(",");
	string Day = Date.substr(i+1, k-i-1);
	// Get the year by getting the substring from the blank
	// following the comma through the end of the string
	string Year = Date.substr(k+2, Date.size());
	string NewDate = Day + " " + Month + " " + Year;
	cout << "Original date: " << Date << endl;
	cout << "Converted date: " << NewDate << endl;
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?