全部评论
struct Interval {
int start;
int end;
Interval() : start(0), end(0) {}
Interval(int s, int e) : start(s), end(e) {}
};
int main()
{
vector <Interval> vec;
Interval i;
char c=' ';
while (c!='\n')
{
scanf("%d,%d%c",&i.start,&i.end,&c);
vec.push_back(i);
}
Solution sol;
vec = sol.merge(vec);
for (vector<Interval>::iterator i = vec.begin(); i != vec.end(); i++)
cout << i->start << ','<<i->end<<' ';
cout<<endl;
system("pause");
return 0;
}
do {cin >> num;}while(cin.getchar() != '\n')
do {}
感谢各位大佬,发现7L@西方玄学,神经网络~ 的方法可以使用
用的笨办法。读进字符串然后解析出来,A了。 #include <vector> #include <iostream> #include <string> #include <sstream> #include <map> using namespace std; struct Person { int vote; int count; }; void fill(vector<int>& v, string s) { string sub; for (int i = 0; i < s.size(); ) { int j = i; if (s[i] >= '0' && s[i] <= '9') { while (s[j] >= '0' && s[j] <= '9') j++; sub = s.substr(i, j - i); stringstream str(sub); int num; str >> num; v.push_back(num); } i = j + 1; } } int main() { string vstr; string wstr; getline(cin, vstr); getline(cin, wstr); vector<int> v; fill(v, vstr); vector<int> w; fill(w, wstr); map<int, Person> votes; for (int i = 0; i < v.size(); i++) { votes[v[i]].count++; votes[v[i]].vote += w[i]; } map<int, Person>::iterator person = votes.begin(); for(map<int, Person>::iterator it = votes.begin(); it != votes.end(); it++) { if (person->second.vote < it->second.vote) person = it; if (person->second.vote == it->second.vote && person->second.count < it->second.count) person = it; } cout << person->first << endl; }
第一种(用c++): while(cin>>first) { char a;cin>>a; cin>>end } 第二种用C: while (1) { scanf("%d", &num1); char c = getchar(); //过滤逗号 scanf("%d", &num2); c = getchar(); //过滤空格 if (c == '\n'){ break; } }
你是说迅雷的笔试题吗? #include <bits/stdc++.h>
using namespace std;
struct Bound{
unsigned int x;
unsigned int y;
Bound(unsigned int _x=0,unsigned int _y=0)
:x(_x),y(_y){}
};
int main()
{
list<Bound> lst;
unsigned int x,y;
while(scanf("%u,%u",&x,&y)){
lst.emplace_back(x,y);
if(getchar()==10) break;
}
lst.sort([](const Bound& a,const Bound& b){
return a.x<b.x;}
);
for(auto it=++lst.begin();it!=lst.end();++it){
auto cur_it = it;//保存当前迭代器
if(cur_it->x <= (--it)->y){
cur_it->x = it->x;
lst.erase(it);
}
it = cur_it;
}
for(const auto& ele:lst){
printf("%u,%u ",ele.x,ele.y);
}
return 0;
}
用 vector 存 while(scanf("%d,%d", &x, &y) != EOF) { ....... }
不定长数组如果确定输入个数的话可以用关键字new来分配动态内存,注意用完后用delete回收;也可以用vector 如果不确定输入个数的话就直接用vector吧,然后判断‘\n’跳出输入 我平常都是这么做,不知道还有没有更好的方法
windows控制台ctrl+z表示结束
我用比较蠢的方法,先全部读进来,然后找空格然后用sscanf.. 突然感觉好像用sstream更简单些..
这跟定不定长有啥关系
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
02-02 15:32
南京信息工程大学 Java
HR_丸山彩同学:你的项目描述里,系统设计讲了很多:MemCube是什么、三级存储架构怎么设计、四种遗忘策略分别是什么。这些面试的时候讲没问题,但简历上不需要这么细。
简历要突出的是影响力,不是实现细节。面试官看简历的时候想知道的是「这个项目有多大价值」,不是「这个项目具体怎么实现的」。实现细节是面试时候聊的
怎么改:技术细节可以精简为一句「采用三级存储架构+四种遗忘策略」,把省出来的篇幅用来写影响力。比如:项目有没有开源?有没有写成技术博客?有没有被别人使用过?
校园经历没有任何信息量,任何人都可以写这句话,写了等于没写。更关键的是,你投的是技术岗,校园活动经历本来就不是加分项。如果非要写,必须写出具体的数字和成果。如果你没有这些数字,那就老老实实删掉 点赞 评论 收藏
分享
01-30 22:03
门头沟学院 Java
用微笑面对困难:我滴妈,【俩月】【实习】【主管】仨debuff吃满了,独立设计开发的项目写了绝大占比的运营板块,你独立开发,那维护、问题复盘、日志更新、bug、策划书全是自己整的? 点赞 评论 收藏
分享