有一个数组a[N]顺序存放0~N-1,要求每隔两个数删掉一个数,到末尾时循环至开头继续进行,求最后一个被删掉的数的原始下标位置。以8个数(N=7)为例:{0,1,2,3,4,5,6,7},0->1->2(删除)->3->4->5(删除)->6->7->0(删除),如此循环直到最后一个数被删除。
开发一个简单错误记录功能小模块,能够记录出错的代码坐在的文件名称和行号。
处理:
1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并)
2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并)
3.输入的文件可能带路径,记录文件名称不能带路径
输入描述:
每组数据为一行一个整数n(小于等于1000),为数组成员数,如果大于1000,则对a[999]进行计算。
输出描述:
一行输出最后一个被删掉的数的原始下标位置。
输入例子:
8
输出例子:
6
//用队列模拟,队首取数,用一个计数器计数,隔2个删一个,其他的重新放到队尾
#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
queue<int> q;
for(int i=0;i<n;i++)
{
q.push(i);
}
int count=0;
while(q.size()!=1)
{
if(count!=2)
{
int b=q.front();
q.pop();
q.push(b);
count++;
}
else
{
q.pop();
count=0;
}
}
int c=q.front();
cout<<c<<endl;
}
return 0;
}
</pre><h5 style="margin:0px; padding:0px; font-weight:400; color:rgb(51,51,51); font-family:arial,STHeiti,'Microsoft YaHei',宋体"><span style="color:rgb(0,0,0)"></span></h5><h5 style="margin:0px; padding:0px; font-weight:400; color:rgb(51,51,51); font-family:arial,STHeiti,'Microsoft YaHei',宋体"><span style="color:rgb(0,0,0)"></span><pre name="code" class="html">输入一个字符串,求出该字符串包含的字符集合
每组数据输入一个字符串,字符串最大长度为100,且只包含字母,不可能为空串,区分大小写。
输入一个字符串,求出该字符串包含的字符集合
每组数据输入一个字符串,字符串最大长度为100,且只包含字母,不可能为空串,区分大小写。
输出描述:
每组数据一行,按字符串原有的字符顺序,输出字符集合,即重复出现并靠后的字母不输出。
输入例子:
abcqweracb
输出例子:
abcqwer
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s;
vector<char> cvec;
while (cin >> s)
{
for (int i = 0; i < s.size(); ++i)
{
auto beg = find(cvec.begin(), cvec.end(), s[i]);
if (beg == cvec.end())
{
cvec.push_back(s[i]);
cout << s[i];
}
}
cout << endl;
s.clear();
cvec.clear();
}
return 0;
}
老师想知道从某某同学当中,分数最高的是多少,现在请你编程模拟老师的询问。当然,老师有时候需要更新某位同学的成绩.
输入描述:
输入包括多组测试数据。 每组输入第一行是两个正整数N和M(0 < N <= 30000,0 < M < 5000),分别代表学生的数目和操作的数目。 学生ID编号从1编到N。 第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩 接下来又M行,每一行有一个字符C(只取‘Q’或‘U’),和两个正整数A,B,当C为'Q'的时候, 表示这是一条询问操作,他询问ID从A到B(包括A,B)的学生当中,成绩最高的是多少 当C为‘U’的时候,表示这是一条更新操作,要求把ID为A的学生的成绩更改为B。
输出描述:
对于每一次询问操作,在一行里面输出最高成绩.
输入例子:
5 7 1 2 3 4 5 Q 1 5 U 3 6
#include "stdafx.h"
#include <iostream>
using namespace std;
int grades[30000];
int max(int x, int y)
{
int temp = grades[x];
int max = x+1;
for(int i=x+1;i<=y;i++)
{
if(temp<grades[i])
{
temp=grades[i];
max=i+1;
}
}
return max;
}
int main()
{
int N,M,x,y;
char J;
while(cin>>N>>M)
{
for(int i=0; i<N;i++)
{
cin>>grades[i];
}
for(int m=0;m<M;m++)
{
cin>>J>>x>>y;
if(J=='Q')
{
if(x>y)
{
int temp2 =x;
x = y;
y = temp2;
}
int temp = max(x-1,y-1);
cout<<temp<<endl;
}
else if(J=='U')
{
grades[x-1] = y;
}
else
cout<<"wrong input"<<endl;
}
}
return 0;
}
开发一个简单错误记录功能小模块,能够记录出错的代码坐在的文件名称和行号。
处理:
1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并)
2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并)
3.输入的文件可能带路径,记录文件名称不能带路径
输入描述:
一行或多行字符串。每行包括带路径文件名称,行号,以空格隔开。 文件路径为windows格式 如:E:\V1R2\product\fpgadrive.c 1325
输出描述:
将所有的记录统计并将结果输出,格式:文件名代码行数数目,一个空格隔开,如: fpgadrive.c 1325 1 结果根据数目从多到少排序,数目相同的情况下,按照输入第一次出现顺序排序。 如果超过8条记录,则只输出前8条记录. 如果文件名的长度超过16个字符,则只输出后16个字符
输入例子:
E:\V1R2\product\fpgadrive.c 1325
输出例子:
fpgadrive.c 1325 1
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
bool compare(pair<string, int> a, pair<string, int> b)
{
return a.second > b.second;
}
int main()
{
string file, input;
vector<pair<string, int>> errors;
while(getline(cin, input))
{
if(input.size()==0) //
{
break;
}
unsigned int f = input.rfind('\\');
file = input.substr(f+1);
errors.push_back(make_pair(file,1));
for(int i=0;i<(errors.size()-1); i++)
{
if(errors[i].first==file)
{
errors[i].second++;
errors.pop_back(); break;
}
}
}
stable_sort(errors.begin(), errors.end(), compare);
int idx = 0;
while(idx<8 && idx<errors.size())
{
string check = errors[idx].first;
int t = check.find(' ');
if(t>16)
errors[idx].first.erase(0, t-16);
cout << errors[idx].first<<' '<<errors[idx].second<<endl;
idx++;
}
}