标签:clu str math code number std 输入 大小 using
#include<iostream> #include<string> using namespace std; struct student{ string name; string number; int score; }; int main(){ int n; cin>>n; student a[n]; int max=0; int min=100; int maxnum,minnum; for(int i=0;i<n;i++){ cin>>a[i].name >>a[i].number >>a[i].score ; if(a[i].score>max){ max=a[i].score; maxnum=i; } if(a[i].score<min){ min=a[i].score; minnum=i; } } cout<<a[maxnum].name <<" "<<a[maxnum].number <<endl; cout<<a[minnum].name <<" "<<a[minnum].number <<endl; return 0; }
注:
1、以空格、tab或回车可分隔不同的字符串
#include<iostream> #include<string> using namespace std; int main(){ string name,number; int score; cin>>name>>number>>score; cout<<name<<" "<<number<<" "<<score<<endl; //输入:abc math123456 123 //输出:abc math123456 123 return 0; }
另:string类型大小比较:两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇‘\0‘为止。
标签:clu str math code number std 输入 大小 using
原文地址:https://www.cnblogs.com/stray-yang/p/13357197.html