#define LOCAL
#include<iostream>
#include<stdio.h>
#define INF 0x3f3f3f3f
using namespace std;
struct Node{
int next;
}node[100005];
int n,m;
int main(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#endif
cin>>n;
int len;
for(int i=1;i<=n;i++){
cin>>len;
if(i!=n){
node[i].next=len;
}else{
node[i].next=len;
}
}
cin>>m;
int start,finish;
for(int i=0;i<m;i++){
cin>>start>>finish;
if(start>finish){
swap(start,finish);
}
int minl=INF;
int temp=0;
int s=start,f=finish;
while(s!=f){//顺时针
temp+=node[s++].next;
}
minl=min(minl,temp);
temp=0;
s=finish,f=start;
while(s!=f){//逆时针
temp+=node[s].next;
if(s==n){
s=1;
}else{
s++;
}
}
minl=min(minl,temp);
cout<<minl<<endl;
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=10010;
int main(){
int a;
while( scanf("%d",&a)&&a ){
cout<<a<<endl;
}
}
回文词: P49
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<ctype.h>
using namespace std;
const int maxn=10010;
const char* rev="A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char* msg[]={"not a palindrome.",
"a regular palindrome.",
"is a mirrored string.",
"is a mirrored palindrome."};
char r(char ch){
if(isalpha(ch)) return rev[ch-'A'];
else return rev[ch-'0'+25];
}
int main(){
char s[maxn];
while(scanf("%s",s)==1){
int m=1,p=1;
int len=strlen(s);
for(int i=0;i<(len+1)/2;i++){
if(s[i]!=s[len-1-i]) p=0;
if(r(s[i])!=s[len-1-i]) m=0;
}
printf("%s -- is %s\n\n",s,msg[m*2+p]);
}
}
竖式问题P43
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=10010;
int main(){
char s[maxn];
while(scanf("%s",s)!=-1){
int cnt=0;
for(int abc=100;abc<1000;abc++){
for(int de=10;de<100;de++){
char buf[100];
int x=abc*(de%10); int y=abc*(de/10); int z=abc*de;
sprintf(buf,"%d%d%d%d%d",abc,de,x,y,z);
int ok=1;
for(int i=0;i<strlen(buf);i++){
if(strchr(s,buf[i])==NULL) ok=0;
}
if(ok){
printf("<%d>\n",++cnt);
printf("%5d\nX%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n",abc,de,x,y,z);
}
}
}
printf("The number of solutions = %d\n",cnt);
}
}