几道题目

#include<cstdio>
#include<algorithm>
using namespace std;


const int maxn = 1000;


int main(){
    int n, q, x, a[maxn],kase = 0;
    while(scanf("%d%d",&n,&q) == 2 && n){//n为大理石的个数,q为所要查询的个数
        printf("case # %d\n",kase++);
        for(int i = 1;i <= n; i++)
            scanf("%d",&a[i]);
        sort(a,a+n);//sort函数的使用方法
        while(q--){
            scanf("%d",&x);
            int p = lower_bound(a,a+n,x) - a;//lowerbound的使用方法
            if(a[p] == x)
                printf("%d fonud at %d\n",x,p+1);
            else
                printf("%d not found");
        
            }
            
        }
        return 0;
    }
    
    


/*
 *输入一个文本,找出所有不同的单词,按字典序从小到大输出
 */
 #include<iostream>
 #include<string>
 #include<set>
 #include<sstream>
 using namespace std;
 
 set<string> dict;//string集合
 
 int main(){
    string s,buf;
    while(cin >> s){
        for(int i = 0; i < s.length(); i++)
            if(isalpha(s[i]))
                s[i] = tolower(s[i]);
            else
                s[i] = ' ';
                
            stringstream ss(s);
            while(ss >> buf)
                dict.insert(buf);
        
        for(set<string>::iterator it = dict.begin();it != dict.end(); ++it)
            cout << *it << "\n";
        return 0;
    }
 }
 
 
 /*映射是从键到值的映射,输入一些单词,找出所有满足以下条件的单词:该单词不能通过字母重排,
  *得到输入文本中的另外一个单词。在判断是否满足条件时,字母不分大小写,但在输出时应该保留输入中
  *的大小写,按字典序排列--->为保证重排后得不到另一个单词,则
 */
 #include<iostream>
 #include<string>
 #include<cctype>
 #include<vector>
 #include<map>
 #include<algorithm>
 using namespace std;
 
 map<string,int> cnt;
 vector<string> words;
 
 //将单词标准化(按字典顺序)
 string repr(const string &a){
    string ans = s;
    for(int i = 1; i < ans.length(); i++)
        ans[i] = tolower(ans[i]);
    sort(ans.begin(), ans.end());
    return ans;
 }
 
 int main(){
    int n = 0;
    string s;
    while(cin >> s){
        if(s[0] == '#') break;
        words.push_back(s);
        string r = repr(s);
        if(!cnt.count(r))
            cnt[r] = 0;
        cnt[r]++;//1表示不存在,即可以写入(0表示存在.)
    }
    
    /*第二次筛选*/
    vector<string> ans;
    for(int i = 0; i < words.size(); i++){
        if(cnt[repr(words[i])] == 1)
            ans.push_back(words[i]);
    }
    
    sort(ans.begin() , ans.end());
    for(int i = 0; i < ans.size(); i++){
        cout<< ans[i]<<"\n";
    }
    return 0;
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
  
  
    



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值