@rg070836rg
2017-06-17T15:03:56.000000Z
字数 3421
阅读 1078
未分类
// 01
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
long long sum=0;
for(int i=1;i<=n;i++)
{
sum+=i*i;
}
cout<<sum<<endl;
return 0;
}
// 02
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
bool judge(int x)
{
//判断整除
if(x%4==0||x%7==0)
return true;
//int转string
char c[10];
snprintf(c, sizeof(c), "%d", x);
if (strstr(c,"44")!=NULL ||strstr(c,"77")!=NULL )
return true;
return false;
}
int main(){
int n;
cin>>n;
int sum = 0;
for(int i=1;i<=n;i++)
if(judge(i))
sum++;
cout<<sum<<endl;
return 0;
}
// 03
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
int n,k,number;
cin>>n>>k>>number;
int a[n],b[n];
for(int i=0;i<n;i++)
a[i]=i+1;
for(int i=0;i<k;i++)
{
int num = 0;
for(int j=0;j<n/2;j++)
{
b[num++] = a[j];
b[num++] = a[j+n/2];
}
for(int m=0;m<n;m++)
a[m]=b[m];
}
cout<<a[number-1]<<endl;
return 0;
}
// 04-1
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
int n,s;
cin>>n>>s;
int a[26],b[26];
for(int i = 0;i<26;i++)
a[i]=b[i]=0;
for(int i = 0;i<n;i++)
{
s=(s*345) %19997;
a[s %26] +=1;
}
for(int i = 0;i<n;i++)
{
s=(s*345) %19997;
b[s %26] +=1;
}
for(int i = 0;i<26;i++)
{
if(a[i]>0)
{
if(a[i]>b[i])
{
a[i]-=b[i];
b[i]-=b[i];
}
else
{
a[i]-=a[i];
b[i]-=a[i];
}
}
}
int sum =0;
for(int i=0;i<26;i++)
sum+=a[i];
cout<<sum<<endl;
return 0;
}
//04-2
#include<iostream>
using namespace std;
int main()
{
int n,s;
cin>>n>>s;
char *a=new char[n];
char *b=new char[n];
for(int i = 0;i<n;i++)
{
s=(s*345) %19997;
a[i]=char(97 + (s %26));
}
for(int i = 0;i<n;i++)
{
s=(s*345) %19997;
b[i]=char(97 + (s %26));
}
int per = n;
cout<<a<<endl;
cout<<b<<endl;
for(int j=0;j<n;j++){
for(int i=0;i<n;i++){
if(a[j] == b[i]){
b[j] = '#';
per--;
break;
}
}
}
/*
for(int j=0;j<n;j++){
for(int i=0;i<n;i++){
if(a[i] == b[j]){
a[i] = '#';
per--;
break;
}
}
}
*/
cout<<a<<endl;
cout<<b<<endl;
cout<<per<<endl;
return 0;
}
//加法
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
string x,y;
cin>>x>>y;
int xlen=x.length();
int ylen=y.length();
stack<int> answer;
int c=0;
while(xlen>0 || ylen>0)
{
int a = xlen>0 ? x[xlen-- -1]-'0' : 0;
int b = ylen>0 ? y[ylen-- -1]-'0' : 0;
int tmp = a+b+c;
answer.push(tmp%10);
c = tmp/10;
}
if(c!=0)
cout<<c;
while(!answer.empty())
{
cout<<answer.top();
answer.pop();
}
return 0;
}
//减法
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
string x,y;
cin>>x>>y;
int xlen=x.length();
int ylen=y.length();
bool flag = true;
if(xlen<ylen || (xlen==ylen && x<y))
{
flag=false;
swap(x,y);
swap(xlen,ylen);
}
stack<int> answer;
int c=0;
while(xlen>0 || ylen>0 )
{
int a = xlen>0 ? x[xlen-- -1]-'0' : 0;
int b = ylen>0 ? y[ylen-- -1]-'0' : 0;
int tmp = (a-b+c+10)%10;
c=a-b+c>=0?0:-1;
answer.push(tmp);
}
if(!flag)
cout<<"-";
bool isout = false;
while(!answer.empty())
{
int x = answer.top();
answer.pop();
if(x==0 && !isout)
continue;
isout = true;
cout<<x;
}
return 0;
}
//乘法
#include<iostream>
#include<string>
#include<stack>
using namespace std;
string add(string x,string y)
{
int xlen=x.length();
int ylen=y.length();
stack<int> answer;
int c=0;
while(xlen>0 || ylen>0)
{
int a = xlen>0 ? x[xlen-- -1]-'0' : 0;
int b = ylen>0 ? y[ylen-- -1]-'0' : 0;
int tmp = a+b+c;
answer.push(tmp%10);
c = tmp/10;
}
string res="";
if(c!=0)
res+=char('0'+c);
while(!answer.empty())
{
res+=char('0'+answer.top());
answer.pop();
}
return res;
}
string mul(string x,char y)
{
string res;
int b = y-'0';
int c = 0;
for(int i=x.length()-1;i>=0;i--)
{
int a = x[i]-'0';
int tmp = a * b + c;
res = char(tmp%10+'0') +res;
c = tmp/10;
}
if(c!=0)
res = char(c+'0') +res;
return res;
}
int main(){
string x,y;
cin>>x>>y;
int xlen=x.length();
int ylen=y.length();
string res="0";
for(int i=y.length()-1;i>=0;i--)
{
string tmp = mul(x,y[i]);
for(int j=0;j<ylen-i-1;j++)
{
tmp+="0";
}
res = add(res,tmp);
}
cout<<res<<endl;
return 0;
}