zoukankan      html  css  js  c++  java
  • 北理工计算机复试上机 2011

    1.输入一组单词(区分大小写),统计首字母相同的
    单词的个数,相同的单词不累加,输出格式:“字母,个数”

     1 // 2011_1.cpp : Defines the entry point for the console application.
     2 //
     3 
     4 #include<iostream>
     5 #include<vector>
     6 #include<string>
     7 using namespace std;
     8 /**
     9 1.
    10 输入一组单词(区分大小写),统计首字母相同的
    11 单词的个数,相同的单词不累加,输出格式:“字母,个数”
    12 */
    13 int main(int argc, char* argv[])
    14 {
    15     vector<string> list;
    16     string s;
    17     cout<<"请输入一组单词,输入00结束"<<endl;
    18     vector<string>::iterator i;
    19     int flag=0;
    20     while(cin>>s){
    21         if(s=="00")break;
    22         flag=0;
    23         for(i=list.begin();i!=list.end();i++){
    24             if((*i)==s)flag=1;    
    25         }
    26         if(flag==0)list.push_back(s);
    27     
    28     }
    29     int count=0;
    30     char x;
    31     for(x='a';x<='z';x++){
    32         count=0;
    33         for(i=list.begin();i!=list.end();i++){
    34             if((*i)[0]==x)count++;
    35         
    36         }
    37         if(count!=0)cout<<x<<" "<<count<<endl;
    38     }
    39     for(x='A';x<='Z';x++){
    40         count=0;
    41         for(i=list.begin();i!=list.end();i++){
    42             if((*i)[0]==x)count++;
    43         
    44         }
    45         if(count!=0)cout<<x<<" "<<count<<endl;
    46     }
    47 
    48     for(i=list.begin();i!=list.end();i++)cout<<(*i)<<" ";
    49     return 0;
    50 }
    2.输入一组单词,(区分大小写),输出其字典排序。
     1 // 2011_2.cpp : Defines the entry point for the console application.
     2 //
     3 
     4 #include<iostream>
     5 #include<string>
     6 #include<vector>
     7 #include<algorithm>
     8 
     9 using namespace std;
    10 
    11 bool ace(string a,string b){
    12     return a<b;
    13 }
    14 
    15 /**
    16 2.输入一组单词,(区分大小写),输出其字典排序。
    17 */
    18 int main(int argc, char* argv[])
    19 {
    20     vector<string> list;
    21     string s;
    22     while(cin>>s){
    23         if(s=="00")break;
    24         list.push_back(s);
    25     }
    26     vector<string>::iterator i;
    27 
    28     sort(list.begin(),list.end(),ace);
    29     for(i=list.begin();i!=list.end();i++)cout<<(*i)<<" ";
    30 
    31     return 0;
    32 }
    3.给一个字符串(aaaa(bbbb(cccc,dddd),eeee(ffff)))该字符串表明的是各个人的层次关系。
    比如aaaa是bbbb和eeee的领导,bbbb是cccc和dddd的领导。现输入一个名称,
    比如ffff,要求输出其领导关系输出:aaaa>eeee>ffff
    (哇,我竟然写了一个如此变态的逻辑,读不懂不要打我,水平有限所致)
     1 // 2011_3.cpp : Defines the entry point for the console application.
     2 //
     3 
     4 #include<iostream>
     5 #include<string>
     6 #include<vector>
     7 #include<stack>
     8 using namespace std;
     9 /**
    10 3.给一个字符串(aaaa(bbbb(cccc,dddd),eeee(ffff)))该字符串表明的是各个人的层次关系。
    11 比如aaaa是bbbb和eeee的领导,bbbb是cccc和dddd的领导。现输入一个名称,
    12 比如ffff,要求输出其领导关系输出:aaaa>eeee>ffff
    13 */
    14 typedef struct {
    15     string data;
    16     int pri;
    17 }node;
    18 int main(int argc, char* argv[])
    19 {
    20     string s;
    21     vector<node> list;
    22     node n;
    23     stack<char> st;
    24     string token;
    25     cout<<"请输入字符串"<<endl;
    26     cin>>s;
    27     int pri=0;
    28     for(int i=0;i<s.length();i++){    
    29         if(s[i]=='('){
    30             if(token.length()>0){
    31                 n.data=token;
    32                 n.pri=pri;
    33                 list.push_back(n);
    34                 //cout<<"token="<<token<<" pri"<<pri<<endl;
    35                 token="";
    36             }
    37             pri++;
    38             st.push('(');
    39             
    40         }else if(s[i]==')'){
    41             if(token.length()>0){
    42                 n.data=token;
    43                 n.pri=pri;
    44                 list.push_back(n);
    45                 //cout<<"token="<<token<<" pri"<<pri<<endl;
    46                 token="";
    47             }
    48             pri--;
    49             st.pop();
    50             
    51         
    52         }else if(s[i]==','){
    53         if(token.length()>0){
    54                 n.data=token;
    55                 n.pri=pri;
    56                 list.push_back(n);
    57                 //cout<<"token="<<token<<" pri"<<pri<<endl;
    58                 token="";
    59             }
    60         
    61         }else {
    62             token+=s[i];
    63         }
    64     }
    65     cout<<"请输入要查找的字符串"<<endl;
    66     vector<node>::iterator zz;
    67 
    68     cin>>s;
    69     for(zz=list.begin();zz!=list.end();zz++){
    70         if((*zz).data==s){
    71             pri=(*zz).pri;
    72             break;
    73         }
    74     }
    75     
    76     vector<node>::iterator xx;
    77     for(int j=pri-1;j>0;j--){
    78         for(xx=zz;xx>=list.begin();xx--)
    79             if((*xx).pri==j){
    80                 s=(*xx).data+">>"+s;
    81                 break;
    82             }
    83     }
    84     cout<<s<<endl;
    85     return 0;
    86 }
  • 相关阅读:
    document.load 和document.ready 两个事件的区别
    undefined和null的区别
    点击返回上一个界面事件
    APP上点击事件时 取消点击的阴影
    MUI控制安卓手机自带的返回键 禁止返回
    css过滤镜实现颜色渐变
    CSS3 Media Queries模板:max-width和min-width
    什么是响应式网页设计?
    实用的CSS3-渐变背景色
    Oracle EBS 报表日期格式问题
  • 原文地址:https://www.cnblogs.com/PPWEI/p/8453912.html
Copyright © 2011-2022 走看看