CPP25. 结构体简单使用
描述
输入描述
键盘依次输入学生的姓名name、年龄age、身高height输出描述
示例1
输入:
张三 20 182.5
输出:
张三 20 182.5
C++ 解法, 执行用时: 2ms, 内存消耗: 316KB, 提交时间: 2021-12-05
#include <iostream> #include <string> using namespace std; struct student { char name[1000]; int age; double height; }; int main() { struct student st; cin>>st.name>>st.age>>st.height; cout<<st.name<<" "<<st.age<<" "<<st.height<<endl; return 0; }
C++ 解法, 执行用时: 2ms, 内存消耗: 332KB, 提交时间: 2021-12-11
#include <iostream> #include <string> using namespace std; struct student { // write your code here...... string name; int age; float height; }; int main() { // write your code here...... student stu1; cin >> stu1.name>>stu1.age>>stu1.height; cout << stu1.name; if(int(stu1.height+0.9)>int(stu1.height)) printf(" %d %.1f",stu1.age,stu1.height); else printf(" %d %.0f",stu1.age,stu1.height); return 0; }
C++ 解法, 执行用时: 2ms, 内存消耗: 384KB, 提交时间: 2021-12-07
#include <iostream> #include <string> using namespace std; struct student { // write your code here...... string name; int age; double height; }; int main() { // write your code here...... student s1; cin>>s1.name>>s1.age>>s1.height; cout<<s1.name<<" "<<s1.age<<" "<<s1.height<<endl; return 0; }
C++ 解法, 执行用时: 2ms, 内存消耗: 388KB, 提交时间: 2022-01-22
#include <iostream> #include <string> #include <iomanip> using namespace std; struct student { // write your code here...... string name; int age; string height; }; int main() { // write your code here...... struct student stu; cin >> stu.name; cin >> stu.age; cin >> stu.height; cout << stu.name << " " << stu.age << " " << stu.height << endl; return 0; }
C++ 解法, 执行用时: 2ms, 内存消耗: 392KB, 提交时间: 2021-12-17
#include <iostream> #include <cstring> using namespace std; struct student { // write your code here...... int age; double height; string name; }; int main() { // write your code here...... string a; int b; double c; cin>>a>>b>>c; student student1; student1.name=a; student1.age=b; student1.height=c; /*strcpy(student1.name,"a"); strcpy(student1.age,"b"); strcpy(student1.height,"c");*/ cout<<student1.name<<" "<<student1.age<<" "<<student1.height<<endl; return 0; }