A1032 Sharing
#include <cstring>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include <iostream>
using namespace std;
const int maxn=100010;
struct NODE{
char data;
int next;
bool flag;
}node[maxn];
int main(){
for(int i=0;i<maxn;i++){
node[i].flag=false;
}
int s1,s2,n,p;
scanf("%d%d%d",&s1,&s2,&n);
int address,next;
char data;
for(int i=0;i<n;i++){
scanf("%d %c %d",&address,&data,&next);
node[address].data=data;
node[address].next=next;
}
for(p=s1;p!=-1;p=node[p].next){
node[p].flag=true;
}
for(p=s2;p!=-1;p=node[p].next){
if(node[p].flag==true)
break;
}
if(p!=-1){
printf("%05d\n",p);
}
else{
printf("-1\n");
}
return 0;
}
A1060 Are They Equal
#include <cstring>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include <iostream>
using namespace std;
int n;
string deal(string s,int& e){
int k=0;
while(s.length()>0&&s[0]=='0'){
s.erase(s.begin());
}
if(s[0]=='.'){
s.erase(s.begin());
while(s.length()>0&&s[0]=='0'){
s.erase(s.begin());
e--;
}
}
else{
while(k<s.length()&&s[k]!='.'){
k++;
e++;
}
if(k<s.length()){
s.erase(s.begin()+k);
}
}
if(s.length()==0){
e=0;
}
int num=0;
k=0;
string res;
while(num<n){
if(k<s.length())
res+=s[k++];
else
res+='0';
num++;
}
return res;
}
int main(){
string s1,s2,s3,s4;
cin>>n>>s1>>s2;
int e1=0,e2=0;
s3=deal(s1,e1);
s4=deal(s2,e2);
if(s3==s4&&e1==e2){
cout<<"YES 0."<<s3<<"*10^"<<e1<<endl;
}else{
cout<<"NO 0."<<s3<<"*10^"<<e1<<" 0."<<s4<<"*10^"<<e2<<endl;
}
return 0;
}
wen_zhi
发布了11 篇原创文章 · 获赞 4 · 访问量 3381
私信
关注