美文网首页
Practice for coding online test

Practice for coding online test

作者: BookThief | 来源:发表于2018-08-06 16:56 被阅读0次
#include<iostream>
#include<string>
#include<vector>
using namespace std;

// 循环读取,cin对象遇到空格上面的结束,所以循环while时,会记录最后一个字符串
int main(){
    string a;
    while(cin>>a);
    cout<<a.size();
    return 0;
}

//循环读取cin对象,每读取到一个就把该对象放入动态数组里
int main(){
    string a;
    vector<string> b;
    while(cin>>a)
        b.push_back(a);
    cout<<b[b.size()-1].size();
    return 0;
}

// getlin直接获取所有输入(只要没有终止符),然后在所有输入上判断。
int main()
{
    string str;
    getline(cin, str);
    int count = 0;
    for(int i = str.size() - 1; i >= 0; i--)
    {
        if(str[i] == ' ')
            break;      
        count++;     
    }
    cout << count << endl;   
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
using namespace std;
//还是使用动态数组接受两个输入。然后遍历判断。
int main(){
    string st;
    vector<string> vst;
    while(cin>>st)
        vst.push_back(st);
    char a = vst[vst.size()-1][0];
    int index = 0;
    for(int i = 0;i<vst[0].size();i++){
        if(tolower(vst[0][i])==tolower(a))
            index++;
    }
    cout<<index;
    return 0;
}



//这题巨坑,注意题目说测试用例不止一组
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;

// 如果每次测试,测试用例只有一组,则用个vector获取所有输入。再把除第一个外的所有数据改成set类型。set会自动排序和去重。
int main(){
    vector<int> nums;
    int n;
    while (cin >> n)
        nums.push_back(n);
    set<int> result(nums.begin() + 1, nums.end());
        //注意set只能用迭代器访问
    for (auto i = result.begin(); i != result.end(); ++i)
        cout << *i << endl;
    return 0;
}

//测试用例是多组时,要将多次测试用例分开
int main(){
    int loop = 0;
    while (cin >> loop)                   //看题目,set容器
    {
        int a[1000], tem, i = 0;
        for (int i = 0; i < loop; i++) cin >> a[i];
        set<int> num(a, a + loop);
        for (set<int>::iterator it = num.begin(); it != num.end(); it++){
            cout << *it << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
using namespace std;


void fuck(string str) {
    if (str == "")
        return;
    if (str.size() <= 8) {
        str.append(8 - str.size(), '0');
        cout << str << endl;
        return;
    }
    cout << str.substr(0, 8) << endl;
    fuck(str.substr(8, str.size()));
}

int main(){
    string st;
    vector<string> vst;
    while (cin>>st){
        vst.push_back(st);
    }
    for (int j = 0; j < vst.size(); ++j){

        fuck(vst[j]);
    }
    return 0;
}


相关文章

网友评论

      本文标题:Practice for coding online test

      本文链接:https://www.haomeiwen.com/subject/wqyivftx.html