全部评论
第一题百分之75%,是因为当字符串长度是0的时候,只输出0
public void testHuaWei3() { int n = 5; int m = 3; int[] w = new int[]{4, 4, 1, 2, 1}; int t = 0; int k = 0; int sum = Integer.MAX_VALUE; while (sum > 0) {
t++; for (int i = 0; i < m; i++) { if (i == 0) {
k = 0; } for (int j = k; j < n; j++) { if (w[j] > 0) {
w[j] = w[j] - 1; k = j + 1; break; }
}
}
sum = 0; for (int i = n - m; i < n; i++) {
sum += w[i]; }
}
System.out.println(t); }
第一道75%,二三AC。问了管理员,按比例给分。
一个小时全AC了。。。就第一题猜空串该输出什么花了点时间。。。
这次的三道题很简单。。。第一题有个坑的地方 空串要输出长度为0
能说说题目吗?
感觉这次题目不是很难,旁边的小兄弟50分钟全AC
第三题题目还记得吗?求分享
/*第一题:数字串*/ #include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cin >> str;
int maxlen = 0;
int len = 0;
string ans, temp;
for (int i = 0; i<str.size(); i++) {
if (str[i]>='0' && str[i]<='9') {
temp+=str[i];
}
else {
temp.clear();
}
if (temp.size() >= ans.size()) {
ans = temp;
}
}
if (ans.empty())
cout << ans.size() << endl;
else {
cout << ans << endl;
cout << ans.size() << endl;
}
}
/*第二题:报数*/ #include <iostream>
#include <vector>
using namespace std;
int main()
{
int m;
cin >> m;
if (m <= 1 || m >= 100) {
cout << "ERROR!" << endl;
return 0;
}
vector<int> arr;
for (int i = 0; i < 100; i++) {
arr.push_back(1);
}
int count = 0;
int num = 100;
int index = 0;
while (num >= m) {
if (arr[index])
count++;
if (count == m) {
count = 0;
arr[index] = 0;
num--;
}
index++;
if (index == 100) {
index = 0;
}
}
for (int i = 0; i < 100; i++) {
if (arr[i]) {
if (num > 1) {
cout << i + 1 << ",";
num--;
}
else
cout << i + 1 << endl;
}
}
return 0;
}
/*第三题:接啤酒*/ #include <iostream>
#include <vector>
#include <set>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
set<int> qq;
for (int i = 0; i < n && i < m; i++) {
qq.insert(arr[i]);
}
for (int i = m; i < n; i++) {
qq.insert(*(qq.begin()) + arr[i]);
qq.erase(qq.begin());
}
while (qq.size() > 1) {
qq.erase(qq.begin());
}
cout << *qq.begin() << endl;
}
#include <iostream>
#include<string>
#include<vector>
//#include<set>
#include<algorithm>
using namespace std;
/**
1. n > m
2. n < m
**/
// 第三题装酒
int main(){
int m, n;
vector<int> w;
// n people
// m shuilongtou
cin >>n>>m;
for(int i =0 ; i< n; i++){
int x; cin >>x ; w.push_back(x);
}
// whe n <=m pick the max val
if(n<=m){
sort(w.begin(),w.end());
cout << *(w.end()-1)<<endl;
return 0;
}
// pick first m
vector<int> ***;
for(int i =0; i< m ; i++)***.push_back(w[i]);
// queue
int cost =0;
size_t i =m;
while(i < w.size()){
sort(***.begin(), ***.end());
int tar=***[0];// smallest
cost += tar;
for(size_t k =0 ; k < ***.size();k++){
***[k]-=tar;
if(***[k]==0&&i<w.size())***[k]=w[i++]; //pull the new one from w. no zero
}
}
// rest cost;
sort(***.begin(),***.end());
cost+=***[m-1];
cout <<cost <<endl;
return 0;
}
//第二题 报数踢人
int main(){
int m ;
cin >>m;
if(m<=1){cout<<"ERROR!"<<endl;return 0;}
if(m>=100){cout<<"ERROR!"<<endl;return 0;}
vector<bool> pp(100,true);
int cc=100, i=0, kill=0;
while(cc>=m){
kill=pp[i]?(kill+1):kill;
if(kill==m){
pp[i]=false;
cc--;
kill=0;
}
i= (i+1)%100;
}
bool first= true;
for(size_t i =0 ; i < pp.size(); i++)
if(pp[i]&&first){
cout <<i+1;
first= false;
}else if(pp[i]){
cout <<","<<i+1;
}
return 0;
}
// 第一题最长连续数字串
int main()
{
string s;
while(cin >>s){
size_t curr_l=0;
string nums="";
string ms="";
for(size_t i =0 ; i< s.size() ; i++)
{
if(s[i]>='0'&&s[i]<='9')
{
curr_l++;
nums+= s[i];
}else{
ms = curr_l>=ms.size()?nums:ms;
curr_l =0;
nums="";
}
}
ms= curr_l>=ms.size()?nums:ms;
if(ms.size()!=0)
cout<< ms<<endl;
cout << ms.size()<<endl;
}
return 0;
}
第3题的接啤酒怎么做啊
第一题AC,第二题71%,第三题60%,我感觉不能AC的原因是时间复杂度太大。第三题应该要用堆做,可是我写个堆时间要很长的,写完了,没时间了,再多给10分钟就AC了
第二题就是约瑟夫环 问题
第一道ac import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.next(); String s = maxS(str); System.out.println(s); System.out.println(s.length()); in.close(); } public static String maxS (String str) { char[] strC = str.toCharArray(); int count=0, result=0, flag=0; for(int i=0; i<strC.length; i++) { if(strC[i]>='0' && strC[i]<='9') { count++; } else { count = 0; } if(count >= result) { flag = i-count+1; result = count; } } String s = ""; if(result > 0) { for(int i=0; i<result; i++) { s += strC[flag+i]; } } return s; } }
第二道,始终不知道哪出了问题,28.7%,坐着怀疑人生 import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; public class Main2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); char[] output = new char[100]; int m = in.nextInt(); NumberOffGame(m, output); in.close(); } static void NumberOffGame(int m, char[] output) { if(m<=1 || m>=100) { System.out.println("ERROR!"); } else { HashMap<Integer, Integer> fc = new HashMap<Integer, Integer>(); for(int i=1; i<=100; i++) { fc.put(i, i); } int count=1; List<Integer> flag = new ArrayList<Integer>(); while(fc.keySet().size() >= m) { Set<Integer> key = fc.keySet(); for(Integer k : key) { if(count == m) { flag.add(k); count = 1; } else { count++; } } for(int i=0; i<flag.size(); i++) { fc.remove(flag.get(i)); } flag.clear(); } count = 0; for(Entry<Integer, Integer> entry : fc.entrySet()) { System.out.printf("%d",entry.getKey()); if(count!=fc.size()-1) { System.out.printf(","); } count++; } } } }
听说隔壁实验室的今晚都三个全AC
第一道卡在75%……
第一题75%,第二题还是75%。。。
完全就是编译器不行啊,IDE上怎么试都没错,一粘网上就不行了
第一题正则就行,但是题目很坑,一直75%,调了40几分钟突然又通知空字符串返回0。。。真是醉了。。。。 match(/\d+/g)就可以全部匹配
相关推荐
06-18 14:44
沈阳师范大学 Java 点赞 评论 收藏
分享
06-01 17:57
山东工商学院 嵌入式硬件工程师 点赞 评论 收藏
分享