2.9万

#include <iostream>
#include <string>
#include <stack>
using namespace std;
/*函数：r进制转换成10进制*/
int rToTen(string n,int r){
//将r进制转为10进制，n是该r进制的字符串表示
int len = n.length();
int ans = 0;
int i = 0;
while(i<len){
ans*=r;
ans+=n[i]-'0';
i++;
}
return ans;
}
//for example：1253 1=1253/1000%10 2=1253/100%10 5=1253/10%10 3=1253/1%10
/*函数：十进制转任意进制*/
string tenToR(int n,int r){
//十进制n转r进制 ，返回字符串s
char str[1005];
stack<int>s;
while(n){
s.push(n%r);
n = n/r;
}
int i = 0;
while(!s.empty()){
switch(s.top()){
case 10:
str[i++] = 'A';
break;
case 11:
str[i++] = 'B';
break;
case 12:
str[i++] = 'C';
break;
case 13:
str[i++] = 'D';
break;
case 14:
str[i++] = 'E';
break;
case 15:
str[i++] = 'F';
break;
default:
str[i++] = s.top()+'0'; //s存储的是int 转成同样数字char类型
}
s.pop();
}
string st = str;
return st;
}

int main(){
cout<<rToTen("10010",2)<<endl;
cout<<tenToR(18,2)<<endl;
}


2019-09-25 12:20

rt

2019-08-16 07:23

blablabla

#### C++ 代码

#include<iostream>
#include<vector>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
char sentence[1024];
scanf("%[^.]",&sentence);// .作为字符串输入的结束符
char *tokenPtr=strtok(sentence," ");//sentence必须是一个char数组，不能是定义成指针形式
vector<string> v;
while(tokenPtr!=NULL){
v.push_back(tokenPtr);
tokenPtr= strtok(NULL," ");
}
string res=v.at(0);
for (int i = 1; i < v.size(); ++i) {
if(res.length()<v.at(i).length()){
res=v.at(i);
}
}
cout<<res<<endl;
return 0;
}



### 算法2

blablabla

#### C++ 代码

blablabla


2019-08-16 06:01

### 题目描述

blablabla

#### 样例

blablabla


#### C++ 代码

#include<iostream>
#include <ctime>

using namespace std;

int main() {
struct tm t1 = { 0 };
struct tm t2 = { 0 };
int seconds;
int a,b,c,d;
cin>>a>>b>>c>>d;
t1.tm_hour=a;
t1.tm_min=b;
t2.tm_hour=c;
t2.tm_min=d;

seconds = difftime(mktime(&t2), mktime(&t1));//转换结构体为time_t,利用difftime,计算时间差
if(seconds<=0){
seconds+=86400;
}
int hour=seconds/3600;
int min=(seconds%3600)/60;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",hour,min);
return 0;
}



### 算法2

blablabla

#### C++ 代码

blablabla


2019-08-15 12:03

### 题目描述

blablabla

#### 样例

blablabla


#### C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int n;
void print(int i){
int space=(n-i)/2;
int star=i;
for (int i = 0; i < space; ++i) {
cout<<" ";
}
for (int i = 0; i < star; ++i) {
cout<<"*";
}
for (int i = 0; i < space; ++i) {
cout<<" ";
}
cout<<endl;

}

int main(){
cin>>n;
int flag=1;
int k=1;
for (int i = 1; k<=n; k++) {
print(i);
if(flag){
i=i+2;
flag=(i==n?0:1);

}
else{
i=i-2;
flag=(i==1?1:0);
}

}

return 0;
}



### 算法2

blablabla

#### C++ 代码

blablabla


2019-08-14 08:49

### 题目描述

blablabla

#### 样例

blablabla


#### C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){

char sentence[1024];
scanf("%s",&sentence);
char *tokenPtr=strtok(sentence,",");//sentence必须是一个char数组，不能是定义成指针形式
string s[3];
for (int i = 0; i < 3; ++i) {
s[i]=tokenPtr;
tokenPtr= strtok(NULL,",");
}
int pos=0;
if((pos=s[0].find(s[1]))==string::npos){
cout<<-1<<endl;
return 0;
}
int pos1=0;
if((pos1=s[0].rfind(s[2]))==string::npos){
cout<<-1<<endl;
return 0;
}
// cout<<pos<<"  "<<pos1<<endl;
if(pos1-pos<=0||pos1-pos<s[1].length())
{cout<<-1<<endl;
return 0;
}
cout<<pos1-pos-s[1].length()<<endl;

return 0;
}



2019-08-14 06:13

### 题目描述

blablabla

#### 样例

blablabla


#### C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int n=0,mins=0;
vector<string> vec;
void fun(string &s){
string last;
for (int i = 1; i <= mins; ++i) {
string tmp=vec.at(0).substr(vec.at(0).length()-i,vec.at(0).length());;
for (int j = 1; j < vec.size(); ++j) {
string  tmp1=vec.at(j).substr(vec.at(j).length()-i,vec.at(j).length());
if(tmp!=tmp1)
{
i==1?s="":s=last;
return;
}
}
last=tmp;
}
s=last;
}

int main(){
while(cin>>n&&n!=0){
vec.clear();
mins=0x3f3f3f;
for (int i = 0; i < n; ++i) {
string str;
cin>>str;
mins=min(mins,(int)str.length());
vec.push_back(str);
}
string s;
fun(s);
cout<<s<<endl;
}
return 0;
}



2019-08-14 03:57

#### C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int fun(const string &str){
for (int i = 1; i <=str.length(); ++i) {
string tmp=str.substr(0,i);
int pre=0;
int offindex = str.find(tmp, 0);
pre=offindex;
while (offindex != string::npos)
{
if(offindex+tmp.length()==str.length()){
return str.length()/tmp.length();
}
offindex = offindex + 1;
offindex = str.find(tmp, offindex);
if(offindex-pre!=tmp.length())
break;
pre=offindex;
}
}
return str.length();
}

int main(){
string a;
while((cin>>a)&&a!="."){
cout<<fun(a)<<endl;
}
return 0;
}



### 算法2

blablabla

#### C++ 代码

blablabla


2019-08-14 02:54

#### C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int fun(string a,string b){
int len=a.length();
while(len--){
if(a.find(b)!=string::npos){
return 1;
}
a.push_back(a[0]);
a.erase(a.begin());
}
return 0;
}
int main(){
string a,b;
cin>>a>>b;
if(fun(a,b)||fun(b,a))
cout<<"true"<<endl;
else
cout<<"false"<<endl;
return 0;
}



### 算法2

blablabla

#### C++ 代码

blablabla


2019-08-13 09:17

#### C++ 代码

//unique函数属于STL中比较常用函数，它的功能是元素去重。
//即”删除”序列中所有相邻的重复元素(只保留一个)。此处的删除，并不是真的删除，
//而是指重复元素的位置被不重复的元素给占领了(详细情况，下面会讲)。由于它”删除”的是相邻的重复元素，所以在使用unique函数之前，
//一般都会将目标序列进行排序。
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int arr[n];
for (int i = 0; i < n; ++i) {
cin>>arr[i];
}
sort(arr,arr+m);
int length=unique(arr,arr+m)-arr;
cout<<sizeof(arr)/sizeof(int)+length-m<<endl;
return 0;
}